Earlier quoted context omitted.
I'm starting to feel like you're not actually reading anything I write. I specifically include interfaces. To quote myself: > Also, maybe eliminate inheritance and force interfaces and composition instead. Implementing an interface meets all the conditions of an is a relationship; no redefinition is necessary. [0] After all, interfaces are nothing more than abstract base classes with no method bodies to inherit. I ha…
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 argu…
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.
class Square implements IRectangle {
private final Rectangle rectangle;
public Square(final double size) {
this.rectangle = new Rectangle(size, size);
}
public double getWidth() {
return this.rectangle.getWidth();
}
public double getHeight() {
return this.rectangle.getHeight();
}
public double getSize() {
return this.rectangle.getWidth();
}
public double setSize(final double size) {
this.rectangle.setWidth(size);
this.rectangle.setHeight(size);
}
}