Describe what you’ve built or ask your questions in enough detail, so others can clearly understand and (hopefully) replicate! Screenshots and lI will be using PHP and SQL to create either a gas, diesel, or electric car.
One option is to use class type inheritance and then create some classes, but doing so often goes down a dead end.
AbstractCar
-id
-discriminator
-commonAttributesToAllCars
GasCar extends AbstractCar
-id, uniqueAttributes, etc
DieselCar extends AbstractCar
-id, uniqueAttributes, etc
ElectricCar extends AbstractCar
-id, uniqueAttributes, etc
Instead, I will be using composition, and restructured my DB as follows:
Car
-id
-commonAttributesToAllCars
-engineId
Engine
-id
-engineAttributes
But now I discover that different gas, diesel, and electric engines require different attributes.
I feel better about using class type inheritance for engines than cars because the entities are smaller and simpler, however, would still rather not if there is a better way.
Car
-id
-commonAttributesToAllCars
-abstractEngineId
AbstractEngine
-id
-discriminator
-commonAttributesToAllEngines
GasEngine extends AbstractEngine
-id, uniqueAttributes, etc
DieselEngine extends AbstractEngine
-id, uniqueAttributes, etc
ElectricEngine extends AbstractEngine
-id, uniqueAttributes, etc
How should this be implemented without using any inheritance?inks to what you built are encouraged.