Object Oriented Software Engineering   View all facts   Glossary   Help
subject > pattern > design pattern > delegation
Next design patternfacade    Updesign pattern    Previous design patterncomposite   

delegation
subjectfact 
delegationhas definition A pattern in which one procedure does nothing more than call another in a neighbouring class; this reduces total coupling in the system2001-08-30 14:55:13.0
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
2001-08-30 14:55:13.0
has context 2001-08-30 14:55:13.0
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
2001-08-30 14:55:13.0
has problem How can you most effectively make use of a method that already exists in the other class?2001-08-30 14:55:13.0
has related patterns Adapter and Proxy patterns2001-08-30 14:55:13.0
has solution
  1. 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
  2. By 'neighbouring', we mean the «Delegate» is connected to the «Delegator» by an association.
  3. Normally, in order to use delegation an association should already exist between the «Delegator» and the «Delegate».
  4. This association needs only to be unidirectional from «Delegator» to «Delegate».
  5. 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.
2001-08-30 14:55:13.0
is a subtopic of 6.7 - The Delegation Pattern2001-08-30 14:55:13.0
is an instance of design pattern2001-08-30 14:55:13.0
design patternhas name2001-08-30 14:55:16.0
has references one or more references which indicate who developed or inspired a pattern2001-08-30 14:55:16.0
should be illustrated using a simple diagram2001-08-30 14:55:16.0
should be written using a narrative writing style2001-08-30 14:55:16.0
patternshould be as general as possible2001-08-30 14:56:56.0
should be described in an easy-to-understand form so that people can determine when and how to use it2001-08-30 14:56:56.0
should contain a solution that has been proven to effectively solve the problem in the indicated context2001-08-30 14:56:56.0

Next design patternfacade    Updesign pattern    Previous design patterncomposite