top | item 47165711

(no title)

AnimalMuppet | 3 days ago

What's wrong with it is, when I extend with a new subtype, I have to fix up the locations that use the type. Potentially all of the locations that use it - I at least have to look at all of them.

With the polymorphic approach, I just have to create the new subtype, and all the users can do the right thing (if they were written with polymorphism in mind, anyway - if they use virtual functions on the base class).

discuss

order

1718627440|3 days ago

Why would I change the users at all instead of just modifying the dispatch method in the super type?

AnimalMuppet|3 days ago

I see. Yes, you can do it that way.

Still... doing it the C++ way, I can just declare the sub type as deriving from the super type, and I don't have to fix up the super type.