Greetings! I am trying to decide on which is the best approach to implement a following scenario:
Vehicle and Part are both "entites" which can be an Item in an Inventory. Vehicle has the usual VIN, Year, Make, Model, Type, etc, etc... while Part has PartNumber, QuantityOnHand, IsPartOfSet, Vendor... When "stocked" in an Inventory as an Item, both have RetailPrice, PurchasePrice, PurchaseDate but at the same time they have a lot of other properties that are not in common (e.g Vehicle has CurrentMileage, NewOrUsed, etc... etc.. while Part has TreshholdCount, LastCountDate, etc, etc..) So as you can see both Part and Vehicle can be in Inventory, but they have very few properties that are share (more that they don't)...
With scenario above, I am trying to decide between several approaches:
Option 1 - Separate classes for everything (no inheritance)
- Vehicle - common vehicle properties (VIN, year, make, model, etc, etc)
- VehicleInventoryItem - has a reference to Vehicle and contains other inventory specific properties (pricing, warranties, status)
- VehicleInventoryManager - singleton with business logic add, remove, notify, etc, etc
- Part
- PartInventoryItem
- PartInventoryManager
I think this approach is most flexible while it suffers for some property repetition. Managers also can have very different methods...
Option 2 - Base class simple inheritance
- Vehicle - same as option 1
- Part - same as option 1
- InventoryItem - base class
- VehicleInventoryItem - extends InventoryItem, references Vehicle
- PartInventoryItem - extends InventoryItem, references Part
- InventoryManager - all methods accept InventoryItem as parameters
With this approach, I am worried about InventoryManager being polluted with different operations needed for parts vs vehicles
Option 3 - Generics
- Item - where T will be part or vehicle (I can even go more specific then, e.g. - VehicleItem : Item)
- Inventory - holds reference to Item
- InventoryManager - singleton that operates on T
In this approach, there is less classes but again I am worried about InventoryManager
Recap
- Vehicle and Part share very few properties when "stocked" in Inventory.
- Inventory management for Vehicle and Part will also be mostly different (parts are "reordered" when qty on hand is low, when vehicle is sold similar one may be purchased but it is unique)
- In my scenario there will be no other objects/models that will be "stockable" (being in Inventory of any kind)
Questions
What does community think? Is there another approach (perhaps interfaces?) If 2 domain objects share at least 1 property (e.g. PurchasePrice), should that warrant having some sort of inheritance (e.g. option 2 or 3)