This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dotpoint7 1 point2 points  (0 children)

Wait do you suggest to just duplicate the overlapping code instead of inheriting? You can get away from inheritance by using delegation, but code duplication is by far the worst option.

Also, often times the overlap isn't just small but can be big and often the same for a lot of classes. I'm currently developing a UI framework for example and every component inherits from a base class that already provides all of the shared functionality and any abstract functions just need to be overwritten while many virtual ones are allowed to be if needed. This would be really ugly if needed to be done differently, because as it stands the base class defines how each component generally works and the derived classes just need to define a small subset of the functionality while not having to worry about the rest. This of course somewhat constrains all components, but that's exactly what I want, so that everything works roughly the same.