Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Swiggy LLD Code
- DESIGN THE FOOD TRACK SCREEN
- // MAP VIEW - track info inside it, ETA etc
- // MARKETING BANNERS - can have horizontal carousel
- // VIDEO WIDGETS
- // IN THE FUTURE IT CAN HAVE SOME OTHER WIDGETS AS WELL
- 1 SCREEN - FOOD TRACK SCREEN
- COMPOSITE_VIEW
- interface CompositeView {
- int getWidth();
- int getHeight();
- void show();
- void updateView();
- int getId();
- }
- class MapView: CompositeView {
- int getWidth() {
- }
- int getHeight() {
- }
- void show() {
- // initialize all the UI elements, ETA, delivery person info to be shown, etc
- }
- void updateView() {
- }
- }
- enum BannerType {
- case horizontalCarousel, offer, promotion
- }
- class Banner: CompositeView {
- init() {
- // do the API call to fetch the banner info and then show it
- }
- int getWidth() {
- }
- int getHeight() {
- }
- void show() {
- // initialize all marketing info needed to be shown by the banner
- }
- void updateView() {
- }
- }
- class VideoWidget: CompositeView {
- int getWidth() {
- }
- int getHeight() {
- }
- void show() {
- // initialize the video from a URL or from a video in the app bundle and start playing it
- }
- void updateView() {
- }
- }
- class FoodTrackScreen {
- private List<CompositeView> compositeViews;
- void add(CompositeView view) {
- compositeViews.add(view);
- }
- void prepareScreen() {
- for (CompositeView view : compositeViews) {
- int heightForView = view.getHeight();
- // Create a subview / assign this much height for this particular CompositeView
- view.show();
- }
- }
- void updateView(int id, String update) {
- for (CompositeView view : compositeViews) {
- if (view.getId() == id) {
- view.updateView(id, update);
- }
- }
- }
- }
- class Driver {
- void demo() {
- FoodTrackScreen foodTrackScreen = new FoodTrackScreen();
- foodTrackScreen.add(new Banner());
- foodTrackScreen.add(new MapView());
- foodTrackScreen.add(new VideoWidget());
- foodTrackScreen.prepareScreen();
- }
- void receiveUpdate(int id, String update) {
- foodTrackScreen.updateView(id, update);
- }
- }
- class NetworkLayer {
- }
- // Banner, Map, Banner, VideoWidget
- Banner - 2, Map - 1, VideoWidget - 3
- [
- {
- "viewId": 2, // Banner
- "title": "Banner Title",
- "subtitle": "Banner Subtitle"
- },
- {
- "viewId": 1, // Map
- "startLocation": "Whitefield, Bangalore",
- "eta": "20 minutes"
- },
- {
- "viewId": 2, // Banner
- "title": "Banner Title 2",
- "subtitle": "Banner Subtitle 2"
- }
- ]
- {
- }
- // Order status, delivery person location, ETA etc dynamic information needs to be handled
- // Server Side Events (SSE) - long-lived HTTP connection
- // Silent Push Notifications
- {
- ""
- }
- // How will I get the update ?
- // How will I update the UI with that update ?
- DE -> SERVER (send location every 5 second)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement