Advertisement
DhruvSaraswat

Swiggy LLD Interview Code

Sep 4th, 2024
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.12 KB | None | 0 0
  1. Swiggy LLD Code
  2.  
  3. DESIGN THE FOOD TRACK SCREEN
  4.  
  5. // MAP VIEW - track info inside it, ETA etc
  6. // MARKETING BANNERS - can have horizontal carousel
  7. // VIDEO WIDGETS
  8. // IN THE FUTURE IT CAN HAVE SOME OTHER WIDGETS AS WELL
  9.  
  10.  
  11. 1 SCREEN - FOOD TRACK SCREEN
  12. COMPOSITE_VIEW
  13.  
  14. interface CompositeView {
  15.     int getWidth();
  16.     int getHeight();
  17.     void show();
  18.     void updateView();
  19.     int getId();
  20. }
  21.  
  22. class MapView: CompositeView {
  23.     int getWidth() {
  24.  
  25.     }
  26.  
  27.     int getHeight() {
  28.  
  29.     }
  30.  
  31.     void show() {
  32.         // initialize all the UI elements, ETA, delivery person info to be shown, etc
  33.     }
  34.  
  35.     void updateView() {
  36.  
  37.     }
  38. }
  39.  
  40. enum BannerType {
  41.     case horizontalCarousel, offer, promotion
  42. }
  43.  
  44. class Banner: CompositeView {
  45.     init() {
  46.         // do the API call to fetch the banner info and then show it
  47.     }
  48.  
  49.     int getWidth() {
  50.  
  51.     }
  52.  
  53.     int getHeight() {
  54.  
  55.     }
  56.  
  57.     void show() {
  58.         // initialize all marketing info needed to be shown by the banner
  59.     }
  60.  
  61.     void updateView() {
  62.  
  63.     }
  64. }
  65.  
  66. class VideoWidget: CompositeView {
  67.     int getWidth() {
  68.  
  69.     }
  70.  
  71.     int getHeight() {
  72.  
  73.     }
  74.  
  75.     void show() {
  76.         // initialize the video from a URL or from a video in the app bundle and start playing it
  77.     }
  78.  
  79.     void updateView() {
  80.  
  81.     }
  82. }
  83.  
  84. class FoodTrackScreen {
  85.     private List<CompositeView> compositeViews;
  86.  
  87.     void add(CompositeView view) {
  88.         compositeViews.add(view);
  89.     }
  90.  
  91.     void prepareScreen() {
  92.         for (CompositeView view : compositeViews) {
  93.            int heightForView = view.getHeight();
  94.            // Create a subview / assign this much height for this particular CompositeView
  95.            view.show();
  96.         }
  97.     }
  98.  
  99.     void updateView(int id, String update) {
  100.         for (CompositeView view : compositeViews) {
  101.             if (view.getId() == id) {
  102.                 view.updateView(id, update);
  103.             }
  104.         }
  105.     }
  106. }
  107.  
  108. class Driver {
  109.     void demo() {
  110.         FoodTrackScreen foodTrackScreen = new FoodTrackScreen();
  111.         foodTrackScreen.add(new Banner());
  112.         foodTrackScreen.add(new MapView());
  113.         foodTrackScreen.add(new VideoWidget());
  114.  
  115.         foodTrackScreen.prepareScreen();
  116.     }
  117.  
  118.     void receiveUpdate(int id, String update) {
  119.         foodTrackScreen.updateView(id, update);
  120.     }
  121. }
  122.  
  123. class NetworkLayer {
  124.  
  125. }
  126.  
  127. // Banner, Map, Banner, VideoWidget
  128. Banner - 2, Map - 1, VideoWidget - 3
  129.  
  130. [
  131.     {
  132.         "viewId": 2, // Banner
  133.         "title": "Banner Title",
  134.         "subtitle": "Banner Subtitle"
  135.     },
  136.     {
  137.         "viewId": 1, // Map
  138.         "startLocation": "Whitefield, Bangalore",
  139.         "eta": "20 minutes"
  140.     },
  141.     {
  142.         "viewId": 2, // Banner
  143.         "title": "Banner Title 2",
  144.         "subtitle": "Banner Subtitle 2"
  145.     }
  146. ]
  147.  
  148. {
  149. }
  150.  
  151. // Order status, delivery person location, ETA etc dynamic information needs to be handled
  152. // Server Side Events (SSE) - long-lived HTTP connection
  153. // Silent Push Notifications
  154.  
  155. {
  156.     ""
  157. }
  158.  
  159. // How will I get the update ?
  160. // How will I update the UI with that update ?
  161.  
  162. DE -> SERVER (send location every 5 second)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement