§Design Food Delivery App
-
OOD fundamental concepts: Inheritance, encapsulation, abstrction and polymorphism
First POJO(Plain Old Java Object), Then methods -
Scenario, Use Cases
- User can search different restaurant
- User can select a restaurant
- User sees a menu
- Restaurant can change the menu any time
- User adds an item from menu
- User orders the food
- User can track the order in real time
- User can cancel the order
- User pays for the order
-
Solution
Design Patterns involved in the design of this app:
- Builder Design Pattern (For adding food item and ordering)
- Iterator Pattern (User Sees Menu)
- Observer Pattern (Track an order in Real Time)
- (Command Design Pattern) Order and cancellation of Food
-
Major Classes
User
Restaurant
Menu
Item
Order
-
Patterns
-
Builder Pattern
-
Iterator Pattern
-
Observer Pattern
Subject —— notify() ——> Observers
<— subscribe(), unsubscribe() —
eg. When DeliveryStatus changes, we can use observery pattern to notify userskafka:queue, pub/sub
-
Command Pattern
eg. In order topulic class CancelFood: IFoodOrderCommands
andpublic class OrderFood: IFoodOrderCommands
, so we can use command pattern:public interface IFoodOrderCommands
java: runnable, callable
-
-
Summary
1
2
3
4class{ /*write class signature first,*/
//implement
//call servers
}
§Reading Materials
- OODmock interview: Design a Vending Machine
- OODmock interview:How to design meeting room schedulingsystem
- Amazon Interview Question for SDE-2s | Design OO food delivery app catering to use cases
- Design OO food delivery app with C# & Design Patterns
§Problem
§760. Find Anagram Mappings | unordered_map
§Longest Common Substring | DP
§718. Maximum Length of Repeated Subarray | DP
double for loop
1 | if (A[i-1] == B[j-1]){ |
§ Bloomberg 高频题 | 航班规划 | Greedy
给你一堆人从纽约飞各个地方开会的 cost。比如
A 去 城市SF, LA的 cost 分别是 200, 300
B 去城市SF, LA的 cost 分别是 200, 400
C 去城市SF, LA的 cost 分别是 100, 400
D 去城市SF, LA的 cost 分别是 320, 210
然后保证一半的人去 SF,一半的人去 LA,使得总的 cost 最小
-
Represent the Input: Two Dimensional Array / Matrix
-
Greedy => number not equal
if constSF>constLA, numLA++
else if constLA>constSF, numSF++
else numSame++ // Equal cost -
Switch smallest difference
-
Check Legal
1
2
3
4if (arr = null || arr.length == 0)
throw new IllegalArgumentException();
if (m%2 != 0)
throw new IllegalArgumentException();Or use
Guava: Preconditions.checkArgument