Reputation: 498
I've read that Delegation Pattern used to "Simulate multiple inheritance in JAVA". I wonder what about languages like Cpp which allows us 'multiple inhertance', is Delegation Pattern still necessary?
Upvotes: 0
Views: 51
Reputation: 1195
I assume that by "Simulate multiple inheritance in JAVA" you mean a class that extends another one and also implements one interface, and has a class variable of a type that also implements that interface, plus the methods that delegate.
For ex.
class A extends B implements C {
private C c;
public void Cmethod {
c.Cmethod();
}
...
}
Indeed, in C++ you do not need to do this, since you already have multiple inheritance. But there are a lot of other uses for delegation. For example, handling events in a GUI toolkit can be achieved using delegation: a component (say button) receives a message and delegates its handling to another component. So a delegate is a valid concept in C++.
Upvotes: 1