A
alex
I don't know whether the subject is proper, sorry for any confusion.
Now, I have a class A, which is not controlled myself and I can only
get an instance of it at runtime. However, I want to do some adapter
work to it, such as altering its interface.
My solution is using the instance of A as a constructor parameter of a
new adapter class B, for example:
class B {
private A a;
public B(A aa) {
a = aa;
}
/* adapter stuff here ... */
}
Of course, it works. But I am now wondering whether there is a
solution using inheritance instead of composition? Is there any
pattern or trick?
Any answer or hint will be appreciated, thanks.
Now, I have a class A, which is not controlled myself and I can only
get an instance of it at runtime. However, I want to do some adapter
work to it, such as altering its interface.
My solution is using the instance of A as a constructor parameter of a
new adapter class B, for example:
class B {
private A a;
public B(A aa) {
a = aa;
}
/* adapter stuff here ... */
}
Of course, it works. But I am now wondering whether there is a
solution using inheritance instead of composition? Is there any
pattern or trick?
Any answer or hint will be appreciated, thanks.