1 / 22

CSE 403 Lecture 14

CSE 403 Lecture 14. Design Patterns. Today’s educational objective. Understand the basics of design patterns Be able to distinguish them from design approaches such as information hiding and layering Be able to find patterns that meet specific needs Know what the Gang of Four is.

ronjones
Download Presentation

CSE 403 Lecture 14

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE 403Lecture 14 Design Patterns

  2. Today’s educational objective • Understand the basics of design patterns • Be able to distinguish them from design approaches such as information hiding and layering • Be able to find patterns that meet specific needs • Know what the Gang of Four is

  3. Experts vs. Novices • Experience • Higher level thought • Chunking • Idioms • Techniques • Examples

  4. Examples of expertise • Chess playing • Experts view pieces in groups • Mathematics • Integration by trigonometric substitution • Programming for (int i = 0; i < n; i++) a[i] = b[i];

  5. Design patterns in Architecture • Alexander: "Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to the problem. In such a way that you can use this solution a million times over, without ever doing it the same way twice."

  6. Design Pattern • Pattern name: Strip mall. • Problem: Make small commercial establishments and franchises accessible to car driving customers. • Solution: Parking area with store fronts facing parking. Uniform construction. • Consequences: Traffic flow, congestion, parking availability, building rents.

  7. Gang of Four • Gamma, Helm, Johnson, Vlissides • Catalog of design patterns for software

  8. Case study • Lexi Editor (Calder) • Document structure • Formatting • Embellishing UI • Multiple look and feel standards • Multiple window systems • User operations • Spelling checking and hyphenation

  9. Document structure • Characters, pictures, lines, words, paragraphs, columns, tables, . . . • Represent uniformly • Recursive solution • Glyph – display object

  10. Composite pattern • Intent • Tree structures • Structure

  11. Composite Pattern • Participants • Component (Graphic) • Leaf • Composite • Client

  12. Composite Pattern • Consequences • Simple client • Easy to extend • Runtime check required to restrict components

  13. Composite Pattern • Implementation issues • Explicit parent references • Sharing components • Child ordering • Responsibility for deletion (in non-GC language)

  14. Document structure • An object allocated for every character! • Solution (trick, hack) • Table of character objects • Reference into the table

  15. Flyweight pattern

  16. Formatting • Break text into lines • Approach – insert row glyphs to break text into lines • Want to allow different algorithms for formatting • Compositor class – formatting algorithm • Composition glyph has a compositor • Compositor is responsible for formatting children

  17. Strategy pattern • Context, strategy pair • Specific algorithms subclass strategy • ConcreteStrategy

  18. UI Embellishment • Add border or scrollbar to component • MonoGlyph extends Glyph • Border extends MonoGlyph • ScrollBar extends MonoGlyph • Decorator Pattern

  19. Multiple look and feel standards • Motif menus, Mac menus • GuiFactory guiFactory = new MotifFactory(); • ScrollBar sb = guiFactory.CreateScrollBar(); • Button bu = guiFactory.CreateButton(); • Abstract Factory Pattern

  20. Supporting Multiple Window Systems • Window Class Hierarchy • WindowImp Class Hierarchy • Extend WindowImp for each different system • Avoid polluting Window Class with system dependencies • Bridge Pattern • Link between Window and WindowImp

  21. User commands and spell check/hyphenation • User commands • Command Pattern • Includes Undo functionality • Spell check and hyphenation • Iterate over words of document • Iterator Pattern and Visitor pattern

  22. Creational Abstract factory, builder, factory method, prototype, singleton Structural Adapter, bridge, composite, decorator, façade, flyweight, proxy Behavioral Chain of responsibility, command, interpreter, iterator, mediator, memento, observer, state, strategy, template method, visitor Original GoF patterns Classification of patterns

More Related