In the code sample below the Rental object is using Movie's fields to do a switch statement. Martin says : this is a bad idea but he does not give any deeper explanation as to why ?
Of course, you can say that this means a lot of coupling between Movie and Rental, or that Movie is badly encapsulated but those are just (almost meaningless) words, again, they don't explain the why? They don't go to the root of the question, so to say. They don't provide much understanding.
What I would like to know if there is a deeper, more general design principle why having a switch on Rental is a bad idea ?
In other words, how does Martin knows that the switch statement is on the wrong object ? Where does he get this insight from ? What is his thought process ?
RegularMovie
,NewReleaseMovie
, andChildrensMovie
, and the logic in eachcase
should be performed in the derived class overload ofgetCharge
.