Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

But that's exactly the same you would need to implement manually when you use composition. When constructing, you also need to construct the contained objects, when doing something that should affect a contained object, you need to dispatch it.

When a method is never overridden, it doesn't need to be in the vtable.



That's not what people usually mean by "composition" though. The whole point of "use composition over inheritance" is to avoid that behavior.


I don't see how you can use composition without eventually calling methods of the contained objects. Every method of the outer object either uses an inner object or it doesn't. Yes, using the inner object doesn't always means just delegating to a single call. You maybe would implement the outer by calling an inner objects method multiple times or different methods, but nothing stops you of doing the same thing with a super class. When you don't call to an inner object, it's the same as you adding another method to the subclass, without it being present in the parent class.

I think composition over inheritance is only about being explicit. That's it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: