A parking lot is a good exercise for object-oriented design, because the rules are simple to state and awkward to implement: a vehicle takes a number of slots based on its length, the slots have to be next to each other, and the system has to keep track of who is parked where. I built a console application in C# to work through that, and it taught me more than the usual inheritance exercises.
The repository is here: https://github.com/AGA7474/Vehicle-Parking-Management-System
The model
Everything starts from one abstract class:
internal abstract class Vehicle : IPrintable { private static int StaticID ;
public int Id { get ; private set ; } public int Price { get ; private set ; } public int Length { get ; private set ; }
public Vehicle ( int price , int length ) { Id = ++ StaticID ; Price = price ; Length = length ; }
public virtual double CalcMoney ( double NumOfHours ) { return NumOfHours * Price ; }
public abstract void PrintReceipt ( double hours , double fees ) ; }
Enter fullscreen mode
Exit…