delegation | has definition A pattern in which one procedure does nothing more than call another in a neighbouring class; this reduces total coupling in the system | |
has antipatterns - Overusing generalization and inheriting the method that is to be reused
- Instead of creating a single method in the «Delegator» that does nothing other than call a method in the «Delegate», you might consider having many different methods in the «Delegator» call the delegate's method? It would be better to ensure that only one method in the «Delegator» calls the method in the «Delegate». If many methods access the method in the «Delegate», then when it changes, you may have to change every method that accesses it
- a method must only accesses neighbouring classes
| |
has context | |
has forces - You want to minimize development cost and complexity by reusing methods
- You want to reduce the linkages between classes
- You want to ensure that work is done in the most appropriate class
| |
has problem How can you most effectively make use of a method that already exists in the other class? | |
has related patterns Adapter and Proxy patterns | |
has solution - Create a method in the «Delegator» class that does only one thing: it calls a method in a neighbouring «Delegate» class, allowing reuse of the method for which the «Delegate» has responsibility
- By 'neighbouring', we mean the «Delegate» is connected to the «Delegator» by an association.
- Normally, in order to use delegation an association should already exist between the «Delegator» and the «Delegate».
- This association needs only to be unidirectional from «Delegator» to «Delegate».
- However it may sometimes be appropriate to create a new association just so you can use delegation - provided this does not increase the overall complexity of the system.
| |
is a subtopic of 6.7 - The Delegation Pattern | |
is an instance of design pattern | |
design pattern | has name | |
has references one or more references which indicate who developed or inspired a pattern | |
should be illustrated using a simple diagram | |
should be written using a narrative writing style | |
pattern | should be as general as possible | |
should be described in an easy-to-understand form so that people can determine when and how to use it | |
should contain a solution that has been proven to effectively solve the problem in the indicated context | |