Brian

23%
Flag icon
This design is called composition because the existing class becomes a component of the new one. Each instance method in the new class invokes the corresponding method on the contained instance of the existing class and returns the results. This is known as forwarding, and the methods in the new class are known as forwarding methods. The resulting class will be rock solid, with no dependencies on the implementation details of the existing class.
Brian
It doesn’t exactly ‘solve’ the access to private members/methods problem. It forces you to reimplement them yourself, which you can then debate the merits of. Definitely can work when you’re augmenting a class. Harder when trying to change one small part of its existing behavior.
Robert
· Flag
Robert
Yea, re-implementing a couple private methods is the best you can hope for, but often you can't even do that because they're the only way to modify private state you need to modify (in which case you'…
Effective Java
Rate this book
Clear rating
Open Preview