Design a parking lot using object-oriented principles?
To design the parking lot system , we will make our own assumption to start with . So that we could keep our design simple and easy to grasp what is happening . As we would be done with the development as per our first assumption. We will gradually increase the dimension of our assumption and enhance the system accordingly.
Our assumption are as below:
1) Parking lot is only ground floor , so there is no multiple level i.e there is only one level.
2) Parking lot has three different kind of parking lot : small parking lot, medium parking lot and large parking lot.
3) There are three different kind of vehicle which needs to be parked.
4) Motorcycle needs to be parked in small parking lot , car needs to be parked in medium parking lot and bus needs to be parked in large parking lot.
As we can see that motorcycle and bus all comes in the category of vehicle. So we will be using the inheritance property of OOPS and will create vehicle abstract class and will keep the common property in it.
Before designing the class diagram for vehicle . Lets think about what are the properties every vehicle must have .
1) Every vehicle must have type like whether it is car, motorcycle or bus.
2) Every vehicle must have license number .
3) Every vehicle must have parking lot type needed in which it needs to be fit in.
All above the minimum must have properties which a vehicle needs to be have. Let's draw the class diagram.
Vehicle Class Diagram
Code for the above Part is as below :
VehicleEnum.java
Vehicle.java
MotorCycle.java
Car.java
Bus.java
Since now we have implemented the vehicle part , now we need to design the paarkingLot par. As we can see that we have three different kind of parking lot space like small, medium and large. Altough we can design the parting system only using variables for parking lot but since we have to use the design principles. We will use the inheritance for this as well.
Comments
Post a Comment