Skip to main content
12 events
when toggle format what by license comment
Jan 5, 2019 at 2:04 comment added IllusiveBrian Then it all goes to hell when you need to store a paddle boat.
Jan 4, 2019 at 23:59 comment added Brandon There is also a difference between a vehicle which requires wheels but has 0 (because they are in the shop being replaced) and a vehicle that has no concept of wheels, like a boat. This is a bit like NULL. If a boat does not have a concept, don't give it wheel traits.
Jan 4, 2019 at 23:56 comment added Brandon There is nothing wrong with saying a boat has 0 wheels. The question is how useful or misleading is that? The moment you start writing code that does things based on whether or not a vehicle has wheels (like if (vehicle.hasWheels()) { vehicle.rotateTires()), you make confusing, inconsistent, and potentially buggy code. If whether a vehicle depends on wheels or not is an important characteristic, then the object model should reflect that (i.e. a WheeledVehicle interface) . When reading code, defining something as having a number of wheels suggests wheels are relevant, and they aren't.
Jan 4, 2019 at 22:01 comment added samus @PeterM "philosophical" thanks, haven't used that one it in a while : )
Jan 4, 2019 at 21:37 comment added Peter M @DDrmmr It's all fine and dandy to say that a boat has zero wheel, and that is a great philosophical point of view. But computers don't do philosophy at all, so it can all fall in a heap when someone accidentally sets the number of wheels of a boat instance to a non-zero value.
Jan 4, 2019 at 20:18 comment added samus @DDrmmr Your point may be more of a physiological argument in subjectivity, but for the boat example in particular I would say it would best be represented by the number of sails, oars, rutters, props/engines, ... So I'd instead rather have an explicitly named field for exactly what is being represented that a generic catch all that could represent the number of wheels or the number of sails.
Jan 4, 2019 at 19:50 comment added D Drmmr My point is that the example is bad. There is nothing conceptually wrong with a vehicle (that happens to be a boat) stating that it has 0 wheels.
Jan 4, 2019 at 19:09 comment added Peter M @DDrmmr It's not that a Boat has 0 wheels, it that Wheels don't even exist as a concept for a Boat - hence your models shouldn't allow for it.
Jan 4, 2019 at 18:51 comment added D Drmmr A boat has 0 wheels. What does that break?
Jan 4, 2019 at 17:21 comment added user949300 One could temporarily accept that 0 is a valid numberOfWheels. However, eventually you might add a roll() method, at which point the subclass idea is looking prescient.
Jan 4, 2019 at 17:14 vote accept samus
Jan 4, 2019 at 17:02 history answered Pete CC BY-SA 4.0