Visitmethod see javaclass es do not contain other

This preview shows page 171 - 191 out of 215 pages.

visitMethod(…) • See this .visitMethod(methods[i]); – JavaClass es do not contain other similar objects, they are not a Composite object Unnecessary code, complexity
172/215 Practice Unnecessary code, complexity – Trade-offs of (most of) design patterns
173/215 Practice Unnecessary code, complexity – Trade-offs of (most of) design patterns Flexibility
174/215 Practice Unnecessary code, complexity – Trade-offs of (most of) design patterns Flexibility Complexity
175/215 Practice Trade-offs of (most of) design patterns – Flexibility Favouring composition over inheritance – Complexity More objects interacting More messages exchanged
176/215 Practice Trade-offs of (most of) design patterns – Flexibility Favouring composition over inheritance Complexity More objects interacting More messages exchanged
177/215 cu : CompilationUnit c : Class m : Method s : Statement m : Main generateCode( ) generateCode( ) generateCode( ) generateCode( ) m : Main cu : CompilationUnit c : Class m : Method s : Statement v : IVisitor accept(IVisitor) accept(IVisitor) accept(IVis itor) accept(IVisitor) open(CompilationUnit) open(Clas s) open(Method) visit(Statement) close(Method) close(Class) close(CompilationUnit)
178/215 cu : CompilationUnit c : Class m : Method s : Statement m : Main generateCode( ) generateCode( ) generateCode( ) generateCode( ) m : Main cu : CompilationUnit c : Class m : Method s : Statement v : IVisitor accept(IVisitor) accept(IVisitor) accept(IVis itor) accept(IVisitor) open(CompilationUnit) open(Clas s) open(Method) visit(Statement) close(Method) close(Class) close(CompilationUnit) Plus the use of reflection!
179/215 Practice Trade-offs of (most of) design patterns – Flexibility Favouring composition over inheritance – Complexity More objects interacting More messages exchanged
180/215 Practice Trade-offs of (most of) design patterns Flexibility Favouring composition over inheritance – Complexity More objects interacting More messages exchanged
181/215 Practice Flexibility – Favour composition over inheritance Allow changing implementation Allow safe inheritance
182/215 Practice Flexibility – Favour composition over inheritance Allow changing implementation Allow safe inheritance Add one level of indirection
183/215 Practice Flexibility – Favour composition over inheritance Allow changing implementation Allow safe inheritance Add one level of indirection and (possibly) Use double-dispatch
184/215 Practice Add one level of indirection “Rather than giving you a lengthy explanation, let me just point you to the Strategy pattern. It is my prototypical example for the flexibility of composition over inheritance.” Erich Gamma, 2005
185/215 Practice Add one level of indirection
186/215 Practice Add one level of indirection
187/215 Practice Add one level of indirection
188/215 Practice Add one level of indirection is-context-inheritance-as-shown-by-head-first-design-patterns-duck-example-ir
189/215
190/215 Practice Add one level of indirection is-context-inheritance-as-shown-by-head-first-design-patterns-duck-example-ir

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture