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

delegation comparison table
Subject have solution have related patterns have context have forces have problem has definition have antipatterns is a subtopic of is a kind of is an instance of
design pattern zero or more related design patternsa contextone or more forcesa sentence or two explaining the main difficulty being tackledA pattern useful for the design of softwarezero or more antipatterns - solutions that are inferior or do not work in this context with the reason for their rejection6.1 - Introduction to Patternspattern 
delegation
  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.
Adapter and Proxy patterns
  • 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
How can you most effectively make use of a method that already exists in the other class?A pattern in which one procedure does nothing more than call another in a neighbouring class; this reduces total coupling in the system
  • 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
6.7 - The Delegation Pattern design pattern

Next design patternfacade    Updesign pattern    Previous design patterncomposite