-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParkingLot.txt
More file actions
204 lines (173 loc) · 5.95 KB
/
ParkingLot.txt
File metadata and controls
204 lines (173 loc) · 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
Requirement Gathering / Clarification:
How many Entrances?
- 1 Entrance
- 1 Exit
- Different type of parking spots:
- 2 Wheeler
- 4 Wheeler
- Payment: Hourly / Minute based charge => Mix
- Floors? => No
Objects:
- Vehicle
1 Vehicle No.
2 Vehicle Type (Enum)
- Ticket
1. Entry Time
2. Parking Spot
- Entrance Gate
1. Find Parking Space (Nearest Parking to the entrance)
2. Update Parking space
3. Generate Ticket
- Parking Spot
1. id
2. isEmpty
3. Vehicle
4. Price
5. Type
- Exit Gate
1. Cost Calculation
2. Payment
3. Update Parking Spot
2 Approaches possible -
1 Top Down
2 Bottom Up <-
Design Patterns Used: Strategy, Factory, Dependency Inversion
Vehicle
_________
vehicleNo: Int
vehicleType: VehicleType
______________________________________________________________________
<< General Class >>
Parking Spot (has-a vehicle)
__________________
id: Int
isEmpty: Boolean
vehicle: Vehicle
price: Int
___________________
parkVehicle(vehicle)
removeVehicle(vehicle)
____________________
(is-a parking spot) (is-a parking spot)
TwoWheelerSpot FourWheelerSpot
Price() { 10 } Price() {20}
ParkingSpotManager (has-a parking spot)
_____________________________________
list: List<ParkingSpot>
_____________________________________
PSManager(list: List<ParkingSpot>) {
this.list = list
}
findParkingSpace() => (has-a parking strategy)
addParkingSpace()
removeParkingSpace()
parkVehicle(vehicle)
removeVehicle(vehicle)
(is-a parking spot manager) (is-a parking spot manager)
TwoWheelerManager FourWheelerManager
_________________________ __________________________
list: List<ParkingSpot> list: List<ParkingSpot>
_________________________ __________________________
TwoWheelerManager() { FourWheelerManager() {
super(list) super(list)
} }
Parking Strategy
NearToEntrance NearToEntranceAndElevator default
____________ _______________________ ____________
find() find()
// Can use a min-heap for each Entrance
E1 - minHeap
E2 - minHeap
.
.
En - minHeap
ParkingSpotManagerFactory (has-a ParkingSpotManager)
____________________________________________
getParkingSpotManager(vehicle): ParkingSpotManager {
vehicleType Basis
return PSM Object
}
______________________________________________________________________
Ticket (has-a vehicle, parking spot)
_____________
entryTime: Long
vehicle: Vehicle
parkingSpot: ParkingSpot
// Getters & Setters
________________________________________________________________________
EntranceGate (has-a ParkingSpotManagerFactory, Ticket)
____________________________________________________
factory: ParkingSpotManagerFactory
parkingSpaceManager: ParkingSpaceManager
ticket: Ticket
findParkingSpace() {
factory(vehicleType).findParkingSpace()
}
bookSpot(vehicle): ParkingSpot
generateTicket(vehicle, parkingSpot)
________________________________________________________________________
ExitGate
_________________________________
paymentMethod: String
parkingSpotManagerFactory: ParkingSpotManager
ticket: Ticket
costComputationFactory: CostComputationFactory
paymentFactory: PaymentFactory
_________________________________
priceCalculation() {
amount = costComputationFactory.getCostComputation(ticket).price()
}
makePayment() {
paymentFactory.getPaymentMethod(paymentMethod).makePayment(amount)
}
removeVehicle() {
parkingSpotManagerFactory.getParkingSpotManager(ticket.vehicle).removeVehicle(ticket.vehicle)
}
CostComputationFactory
____________________
getCostComputation(ticket) {
ticket.vehicle.vehicleType basis
return CostComputation Obj // (Two/Four Wheeler)
}
CostComputation (has-a Pricing Strategy)
_____________________________
pricingStrategy: PricingStrategy
price(ticket) {
pricingStrategy.price(ticket)
}
TwoWheelerCostComputation FourWheelerCostComputation
________________________ _________________________
TwoWheelerCostComputation() { FourWheelerCostComputation() {
super(Hourly()) super(Minute())
} }
PricingStrategy
Default Hourly MinuteBasis
_____________ ________ ____________
price(ticket) { price(ticket) { price(ticket) {
return parkingSpot.price hours = currTimeH - ticket.etH minutes = currTimeM - ticket.etM
} hours*parkingSpot.price minutes*parkingSpot.price
} }
PaymentFactory
____________________
getPayment(paymentMethod) {
paymentMethod basis
return Payment Obj // (Cash/Card/UPI)
}
Payment
_______________________________
paymentStrategy: PaymentStrategy
_______________________________
makePayment(amount) {
paymentStrategy.makePayment(amount)
}
CardPayment CashPayment
_________________ _______________
CardPayment() { CashPayment() {
super(Card()) super(Cash())
} }
PaymentStrategy
Default Cash Card
_____________ ________ ____________
makePayment(amount) { makePayment(amount) { makePayment(amount) {
// save in cash table // save in cash table // save in card table
} }