Skip to main content

Design an Parking lot system

Let's consider below are the requirements for parking lot. Based on these requirements we will have to design a parking lot.

Requirements
  • The parking lot has multiple slots.
  • The parking lot can park motorcycles, cars, and buses.
  • The parking lot has small slots, compact slots, and large slots.
  • A motorcycle can park in any slot.
  • A car can park in either a single compact slot or a single large slot.
  • A bus can park only in a single large slot.

We can devise below use cases from above requirement.

Use cases
  • Any vehicle enters and asks for free parking slot ID.
  • If any appropriate parking slot is available, vehicle will get assigned parking slot and that parking slot will be blocked for parking till vehicle leaves the slot.
  • Any vehicle when leaves the parking slot, the same slot will be free for parking other vehicles.
  • If appropriate parking slot (to fit the vehicle) is not available, parking lot will return parking full message.

Lets break up the use cases in different module of functionality.

Parking Lot
  • Parking lot has multiple slots.
  • Parking lot can display is parking is full.
  • Parking lot can tell if given vehicle can be parked or not.
  • Parking lot can allot slot for vehicle.
  • Parking lot can clear allotted slot for vehicle.
  • Parking lot has Parking slot allotter.

Parking slot allotter
  • Parking slot allotter allots the parking slot based  on below algorithm
    • motorcycle can park in any slot
    • car can park in either a single compact slot or a single large slot.
    • bus can park only in a single large slot.
  • If no slot is free for vehicle return, Parking Full message.

Parking Slot
  • Parking slot has type.
  • Parking slot has status.
  • Parking slot has ID.
  • Parking slot can tell if given vehicle can be fit in the slot.

Vehicle
  • Vehicle has a size (small, compact, large), which states how much space required to park
  • Vehicle has type.
  • Vehicle has park and leave parking functionality. 

Slot Type
  • Small
  • Compact
  • Large

Vehicle Type
  • Motorcycle
  • Car
  • Bus

Slot Status
  • Free
  • Occupied


We need to take care that we should not derive individual vehicle type from vehicle, like Car, Bus etc.. Because tomorrow if slot is supporting 10 additional types of vehicle there will be class explosion and we are not much interested in vehicle types here but we are only interested in size of vehicle. Same analogy applies for the parking slot.

Comments

Popular posts from this blog

How to boot Samsung Galaxy SL( GT-I9003) in recovery mode

** I Will Not responsible for any damage done with use of below mentioned methods. ** Power off your Samsung Galaxy SL (GT- I9003) to start in recovery mode. Once you have power off the phone, press and Hold Volume UP and Home button. Make sure you have hold volume up, don't press in  the middle of the volume buttons.  Now keep pressing these two buttons(VOL UP + HOME) and presspower button for 2-3 seconds. Release only power button, but keep pressing Volume Up + Home Button, until you see the screen shown below. Once you see recovery screen release the Home button else your phone will restart as first selected option will be restart and pressing home will make that happen.

In the recovery mode, volume up & down act as a up scroll and down scroll buttons, by pressing Home button you will be able to click the selected option.

How to flash CWM Recovery to Samsung Galaxy SL( GT-I9003) using Odin

** I Will Not responsible for any damage done with use of below mentioned methods. ** To flash the CWM recovery to your Samsung Galaxy SL you will require to following things in place: Odin  : you can download it from here.CWM Recovery image : you can download it from here. Thanks to XDA-developers. USB driver to connect your phone with computer. Install Samsung Kias so it will install the USB driver. Once you have downloaded above required items and installed the USB driver, reboot you phone to download mode. You can read how to reboot phone in download mode from here. Now connect the phone with USB cable to computer. 
Extract the Odin from the zip file that you have downloaded at some location on your computer and launch the Odin executable by double clicking it. Wait for Odin to detect your phone.You will be able to see it in yellow once detected on odin screen as shown below.
Click the PDA button to select the CWM recovery image. Once you have selected the recovery image, check the od…

Exception handling with RestTemplate

Spring framework offers RestTemplate for consuming RESTful services. Recently I used RestTemplate for consuming one of the third party RESTful service.

RestTemplate offers 'ResponseErrorHandler'; which you can extend to decide which are errors for you and how to handle those error. You can override hasError and handleError methods of ResponseErrorHandler.
In handleError you can throw customException if you want, as outlined in below code.

import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpResponse; import org.springframework.web.client.ResponseErrorHandler; import java.io.IOException; public class RestTemplateErrorHandler implements ResponseErrorHandler { @Override public void handleError(ClientHttpResponse response) throws IOException { throw new MyCustomException(response.getStatusText(), response.getStatusCode()); } @Override public boolean hasError(ClientHttpResponse response) throws IOException …