1
play

1 Gang of Four Case study Lexi Editor (Calder) Gamma, Helm, - PDF document

Todays educational objective CSE 403 Understand the basics of design Lecture 14 patterns Be able to distinguish them from design approaches such as information hiding Design Patterns and layering Be able to find patterns that


  1. Today’s educational objective CSE 403 � Understand the basics of design Lecture 14 patterns � Be able to distinguish them from design approaches such as information hiding Design Patterns and layering � Be able to find patterns that meet specific needs � Know what the Gang of Four is Experts vs. Novices Examples of expertise � Experience � Chess playing � Higher level thought � Experts view pieces in groups � Mathematics � Chunking � Idioms � Integration by trigonometric substitution � Programming � Techniques � Examples for (int i = 0; i < n; i+ + ) a[i] = b[i]; Design patterns in Architecture Design Pattern � Alexander: "Each pattern describes a � Pattern name: Strip mall. problem which occurs over and over � Problem: Make small commercial establishments and franchises again in our environment, and then accessible to car driving customers. describes the core of the solution to the problem. In such a way that you can � Solution: Parking area with store fronts facing parking. Uniform construction. use this solution a million times over, � Consequences: Traffic flow, congestion, without ever doing it the same way parking availability, building rents. twice." 1

  2. Gang of Four Case study � Lexi Editor (Calder) � Gamma, Helm, Johnson, Vlissides � Document structure � Catalog of design � Formatting patterns for � Embellishing UI software � Multiple look and feel standards � Multiple window systems � User operations � Spelling checking and hyphenation Document structure Composite pattern � Characters, pictures, lines, words, � Intent paragraphs, columns, tables, . . . � Tree structures � Represent uniformly � Structure � Recursive solution � Glyph – display object Composite Pattern Composite Pattern � Participants � Consequences � Component (Graphic) � Simple client � Leaf � Easy to extend � Composite � Runtime check required to restrict components � Client 2

  3. Composite Pattern Document structure � Implementation issues � An object allocated for every character! column � Explicit parent references � Solution (trick, hack) � Sharing components row row row � Table of character � Child ordering objects a p p a r e n t � Responsibility for deletion (in non-GC � Reference into the language) a b c d e f g h i j k l m table n o p q r s t u v w x y z Flyweight pattern Formatting � Break text into lines FlyweightFactory Flyweight � Approach – insert row glyphs to break text GetFlyweight(key) Operation(extrinsicState) flyweights into lines � Want to allow different algorithms for formatting ConcreteFlyweight UnsharedConcreteFlyweight Operation(extrinsicState) Operation(extrinsicState) � Compositor class – formatting algorithm intrinsicState allState � Composition glyph has a compositor Client � Compositor is responsible for formatting children Strategy pattern UI Embellishment � Context, strategy pair � Add border or scrollbar to component � Specific algorithms subclass strategy � MonoGlyph extends Glyph � Border extends MonoGlyph � ConcreteStrategy � ScrollBar extends MonoGlyph � Decorator Pattern 3

  4. Multiple look and feel Supporting Multiple Window standards Systems � Window Class Hierarchy � Motif menus, Mac menus � GuiFactory guiFactory = new MotifFactory(); � WindowImp Class Hierarchy � ScrollBar sb = guiFactory.CreateScrollBar(); � Extend WindowImp for each different system � Button bu = guiFactory.CreateButton(); � Avoid polluting Window Class with system dependencies � Abstract Factory Pattern � Bridge Pattern � Link between Window and WindowImp User commands and spell check/hyphenation Classification of patterns � User commands Creational � Original GoF patterns Abstract factory, builder, � factory method, prototype, � Command Pattern singleton Structural � � Includes Undo functionality � Adapter, bridge, composite, decorator, façade, flyweight, � Spell check and hyphenation proxy Behavioral � � Iterate over words of document � Chain of responsibility, command, interpreter, iterator, � Iterator Pattern and Visitor pattern mediator, memento, observer, state, strategy, template method, visitor 4

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend