|
|
|
|
|
by tigershark
3625 days ago
|
|
You wrote this: "Inheritance is nothing but composition with some default implicit virtual method routing."
In response to my post where I said that inheritance and composition are two different tools and doesn't make sense to say that one is always better than the other.
So it seems to me that you think that inheritance and composition are the same concepts given your words that I quoted and given that you were arguing with my definition of different tools. Edit:
I don't see any composition in your example, just an interface implementation. |
|
EDIT: Notice how I can enforce the invariants of `Square`, while composing a `Rectangle` and implementing `IRectangle`. This works because composition allows me to encapsulate the problematic setter methods of `Rectangle`, which is not something I can do if I inherit it.