3 ms·
Until you want to model a bar-fight and then a chair (a piece of furniture) becomes a weapon, i.e. "class Chair: Furniture{}" turns into "Class Chair: Weapon {}
by paganel 9y ago
Until you want to model a bar-fight and then a chair (a piece of furniture) becomes a weapon, i.e. "class Chair: Furniture{}" turns into "Class Chair: Weapon {}". Or when the winter gets tougher and longer and "class Chair: Furniture{}" changes into "class Chair: Firewood{}". I know that there's probably a "solution" involving object "composition", but that would only mask the problem, will not really solve it.
- yojex 9y agoHonest question: does anyone have a clean solution to this problem? I've run into this often and always end up hacking something ugly to make it work.
- bushin 9y agoYou probably want to solve "the expression problem".
- bushin 9y agoThat's why protocol extensions were implemented.
- cellularmitosis 9y agoI'm not sure I understand your objection. Those are protocols, so Chair can adhere to all of them at once. class Chair: Furniture, Weapon, Firewood {}