I am trying to learn Design practices and OOPs. I am using parking lot problem as sample to start.
I have a GeneralParkingLot interface and a Vehicle interface. GeneralParkingLot has only one function returnParkingLotSize, Vehicle interface has multiple Vehicle attributes.
I have created a class DowntownParkingLot which extends GeneralParkingLot and has other attributes like listOfCars, availableSlots etc. and a Car Class which extends Vehicle class.
I have a HandlerClass which handles incoming command and inside that class I have decalared a DownTownParkingLot object and multiple functions to handle commands, so in each function I just pass the object of DowntownParkingLot and operate on it.
I have created different services like CreateParkingLotObject, ParkACar, FreeASlot etc. which are called by the command handler.
I have also created unit Tests to test my application.
My problem is if I want to extend my current parking lot to have additional functionality like lets say multiple floor attribute or If I want to now handle multiple parking lots instead of one, so what would be the best way to extend my GeneralParkingLot class or DowntownParkingLot class. I have also read about adapter and decorator patterns, but I think those are useful when I am already following a particular design pattern from start, In my case I didnt follow any particular pattern, so what would be the best way to extend my code. I am asking this because sometimes we encounter a class which is not made according to any design pattern and is being used in multiple places (like a lot of API's etc), so what is the best way to extend such a code. Is refactoring from start the only option? or creating new classes which inherit from old classes? What would be the best way? Also I would like to use the already created unit tests as much as possible and not rewrite same test cases again.
Aucun commentaire:
Enregistrer un commentaire