3 ms·
For the Vehicle example the conclusion wasn't that the Vehicle abstraction was premature, it was to prefer Composition and Interfaces over Inheritance which is
by djtango 2y ago
For the Vehicle example the conclusion wasn't that the Vehicle abstraction was premature, it was to prefer Composition and Interfaces over Inheritance which is a well discussed idea around OO design.
The Vehicle example is relatable to day to day work but for me the Vehicle abstraction seems reasonable. The mistake is not that a Bike is or isn't a vehicle but rather that the abstractions should align with the business usage: a bicycle doesn't share much in common with a car, the company just wants to rent them out.
So most the stuff that they will share in common will be around the sales/rental part of the business logic. You wouldn't expect them to really be displayed together anywhere either. So I wouldn't be trying to force a Bike into a Vehicle, I'd be looking for the seams related to the truly common operations on Bikes vs Cars and look to extract interfaces or extend polymorphism there