Copyright © 1995-2004 Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-5 PS95&96-MEF-L9-5 Dr. M.E. Fayad  Document Structure.

Slides:



Advertisements
Similar presentations
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Creational Patterns - Page L4-1 PS95&96-MEF-L11-1 Dr. M.E. Fayad Creationa l Paradigm.
Advertisements

Tutorial 12: Enhancing Excel with Visual Basic for Applications
Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
1 Structural Design Patterns - Neeraj Ray. 2 Structural Patterns - Overview n Adapter n Bridge n Composite n Decorator.
[Course Title] [Module Title]
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
Plab – Tirgul 12 Design Patterns
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Structural Patterns - Page L6-1 PS95&96-MEF-L13-1 Dr. M.E. Fayad Creationa l Paradigm.
GoF: Document Editor Example
Adapted from Prof. Necula CS 169, Berkeley1 Design Patterns V Software Engineering Lecture 9, Spring 2006 Clark Barrett, New York University.
Copyright © 1995 –2004 Active Frameworks Inc. - All Rights Reserved - V2.0Behavioral Patterns - Page L8-1 PS95&96-MEF-L15-1 Dr. M.E. Fayad Creationa l.
Design Patterns David Talby. This Lecture n Patterns for a User Interface u Representing a Document F Composite, Flyweight, Decorator u Writing Portable.
GoF: Document Editor Example A Case Study.
Copyright © Active Frameworks, Inc.. - All Rights Reserved - V2.0 Introduction - Page L1-1 PS95&96-MEF-L1-1 Dr. M.E. Fayad Creationa l Paradigm.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
Basic Design Patterns 2. Designing a Document Editor Gabriel Mañana Ed. 453 Of. 120 Ext unal.edu.co.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Lecture 4: More UML Diagrams, Patterns MISM Summer 2001.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
Lexi Case Study A WYSIWYG document editor.
Lecture 4: More UML Diagrams, Patterns MISM/MSIT Fall 2001.
Katie C. O’Shea Dennis T. Tillman 11 February 2K2 Flyweight.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
© 2008 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice Design Patterns Case Study: Designing.
More OOP Design Patterns
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Design Patterns.
UNIT-II1 Chapter-II A Case Study: Designing a Document Editor:
Prof. Aiken CS 169 Lecture 51 Design Patterns CS169 Lecture 5.
Design a Document Editor Oksana Protsyk Yaroslav Kaplunskiy.
A Case Study: Designing a Document Editor “ Lexi ”
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
ISP666 MVC & Design Patterns. Outline Review Event Programming Model Model-View-Controller Revisit Simple Calculator Break Design Patterns Exercise.
Productivity Programs Common Features and Commands.
Lexi case study (Part 2) Presentation by Matt Deckard.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
GoF: Document Editor Example Rebecca Miller-Webster.
CSE 403 Lecture 14 Design Patterns. Today’s educational objective Understand the basics of design patterns Be able to distinguish them from design approaches.
1 Lexi Case Study A WYSIWYG document editor. Mix text and graphics freely in various formatting styles. The usual –Pull-down menus –Scroll bars –Page.
Structural Design Patterns
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns V More Structural Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
05/26/2004www.indyjug.net1 Indy Java User’s Group May Knowledge Services, Inc.
STAT 598W Lecture 18 Design Patterns. A "hot topic" in O-O research Started by the book Design Patterns: Elements of Reusable Object-Oriented Software.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
CS212: Object Oriented Analysis and Design Lecture 39: Design Pattern-III.
Advanced Object-oriented Design Patterns Creational Design Patterns.
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
Design Patterns. Outline Purpose Purpose Useful Definitions Useful Definitions Pattern Overview Pattern Overview.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns: MORE Examples
Case Study 1: Designing a Document Editor
Software Design and Architecture
Chapter-II A Case Study:
object oriented Principles of software design
Design Patterns, conclusion
Software Engineering Lecture 7 - Design Patterns
Design Patterns A Case Study: Designing a Document Editor
Jim Fawcett CSE776 – Design Patterns Summer 2003
A Case Study: Designing a Document Editor
Structural Patterns: Adapter and Bridge
Strategy Design Pattern
Creational Patterns.
Presentation transcript:

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-5 PS95&96-MEF-L9-5 Dr. M.E. Fayad  Document Structure Goals Recursive Composition Glyphs Design Patterns: Composite Pattern

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-6 PS95&96-MEF-L9-6 Dr. M.E. Fayad  Document Structure: Goals & Constraints Maintaining the document’s physical structure Generating and presenting the document visually Mapping positions in the visual rendition to elements in the internal representation Using one set of formatting and manipulation mechanisms to deal with both text and graphics

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-7 PS95&96-MEF-L9-7 Dr. M.E. Fayad  Document Structure: Recursive Composition Q q Q q space composite (column) composite (row) composite (row) composite row Recursive Composition of text and graphics Object Structure for Recursive Composition Recursive composition is a common way to represent hierarchically structured information by building increasingly complex elements out of simpler ones.

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-8 PS95&96-MEF-L9-8 Dr. M.E. Fayad  Document Structure: Glyphs A Glyph is an abstract class. Its subclasses are specialized to support different graphical elements, both primitive (characters and images) and structural (rows and columns). Glyphs’ responsibilities: They know 1. How to draw themselves 2. The space they occupy 3. Their children and parent 4. A low-level presentation for themselves

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-9 PS95&96-MEF-L9-9 Dr. M.E. Fayad  Document Structure: Composite Pattern Recursive composition can be used to represent potentially complex, hierarchical structure Programming languages can’t express this concept directly Composite pattern is used to document the recursive composition technique as it manifests itself in object-oriented systems Composite captures the essence of recursive composition in object-oriented terms

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-10 PS95&96-MEF-L9-10 Dr. M.E. Fayad Goals & Constraints Encapsulating the Formatting Algorithm Compositor and Composition Design Patterns: Strategy Pattern  Formatting

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-11 PS95&96-MEF-L9-11 Dr. M.E. Fayad Representation and formatting are distinct: The ability to capture the document’s physical structure doesn’t tell us how to arrive at a particular structure. The editor must break text into lines, lines into columns, and so on, taking into account the user’s desires. Constraints : –Flexibility –Changeability –The user configurations Formatting = breaking a collection of glyphs into lines, breaking lines into columns, and breaking columns into pages. The terms formatting and linebreaking are used interchangeably.  Formatting: Goals & Constraints

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-12 PS95&96-MEF-L9-12 Dr. M.E. Fayad Formatting algorithms tend to be complex. The design of Lexi: –Easy to change the formatting algorithms at least at the compile- time, if not at the run-time as well. –Encapsulate the formatting algorithm in an object. This will isolate the algorithm and make it easily replaceable. More specifically: –Define a separate class hierarchy for objects that encapsulate formatting algorithms –The root of the hierarchy define an interface that supports a wide- range of formatting algorithms, and each subclass will implement an interface to carry out a particular algorithm –Then, we can introduce a Glyph subclass that will structure its children automatically using a given algorithm object  Formatting: Encapsulating the Formatting Algorithm

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-13 PS95&96-MEF-L9-13 Dr. M.E. Fayad  Formatting: Compositor & Composition Compositor Compose() SetComposition() Glyph::Insert(g, i) compositor.Compose() Composition Insert(Glyph, g, int i) Glyph Insert(Glyph, int i) children ArrayCompositor Compose() TextCompositor Compose() SimpleCompositor Compose() compositor composition Composition and Compositor Class Relationships

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-14 PS95&96-MEF-L9-14 Dr. M.E. Fayad Encapsulating an algorithm in an object is the intent of Strategy Pattern Compositors are strategies; they encapsulate different formatting algorithms A composition is the context for a compositor strategy  Formatting: Strategy Pattern Strategy Pattern The key to applying the pattern to a particular problem is coming up with general strategy and context interfaces that support a broad range of algorithms.

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-15 PS95&96-MEF-L9-15 Dr. M.E. Fayad  Embellishing the UI Goals & Constraints Transparent Enclosure Monoglyph Design Patterns: Decorator Pattern

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-16 PS95&96-MEF-L9-16 Dr. M.E. Fayad Two embellishments in Lexi’s user interface: The first adds a border around the text to demarcate the page of text The seconds adds scroll bars that let the user view different parts of the page Shouldn’t use inheritance to add embellishments to the user interface, why? –To achieve flexibility »to make it easy to add or remove these embellishments (especially at run-time) and without changing other classes  Embellishing the UI: Goals & Constraints

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-17 PS95&96-MEF-L9-17 Dr. M.E. Fayad Transparent enclosure combines the notion of: 1. Single-child (or single-component) composition and 2. Compatible interface Clients generally can’t tell whether they are dealing with the component and its enclosure, especially if the enclosure delegates all its operations to the component. But the enclosure can also augment the component’s behavior by doing work of its own before and after delegating an operation. The enclosure can also effectively add state to the component.  Embellishing the UI: Transparent Enclosure

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-18 PS95&96-MEF-L9-18 Dr. M.E. Fayad  Embellishing the UI: Monoglyph MonoGlyph Glyph Draw(Window) component Draw(Window) Scroller Draw(Window) Border Draw(Window) DrawBorder(Window) MonoGlyph Class Relationships

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-19 PS95&96-MEF-L9-19 Dr. M.E. Fayad Decorator Pattern The Decorator pattern captures class and object relationships that support embellishment by transparent enclosure. In the Decorator pattern, the term embellishment refers to anything that adds state or behavior to an object.  Embellishing the UI: Decorator Pattern

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-20 PS95&96-MEF-L9-20 Dr. M.E. Fayad  Supporting Multiple Look-and- Feel Standards Goals & Constraints Abstracting Object Creation Factories and Product Classes Design Patterns: Abstract Factory Pattern

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-21 PS95&96-MEF-L9-21 Dr. M.E. Fayad - The Lexi’s design goals are: To make it conform to multiple existing look- and-feel standards To make it easy to add support for new standards as they emerge - This is a portability issue  Supporting Multiple Look-and-Feel Standards: Goals & Constraints The Lexi’s Design must support ultimate flexibility: Changing Lexi’s look and feel at run-time

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-22 PS95&96-MEF-L9-22 Dr. M.E. Fayad Assumptions: A set of abstract Glyph subclasses for each category of widget glyph A set of concrete subclasses for each abstract subclass that implement different look-and-feel standards Lexi must distinguish between widget glyphs for different look-and-feel styles This can be achieved by abstracting the process of object creation  Supporting Multiple Look-and-Feel: Abstracting Objects Creation

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-23 PS95&96-MEF-L9-23 Dr. M.E. Fayad  Supporting Multiple Look-and-Feel: Factories & Product Classes return new MotiScrolBar GUIFactory CreateScrollBar() CreateButton() MotiFactory CreateScrollBar() CreateButton() PMFactory CreateScrollBar() CreateButton() MacFactory CreateScrollBar() CreateButton() return new MotiButton return new PMScrolBar return new PMButton return new MacScrolBar return new MacButton GUIFactory Class Hierarchy

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-24 PS95&96-MEF-L9-24 Dr. M.E. Fayad  Supporting Multiple Look-and-Feel: Factories & Product Classes (cont’d) Glyph Abstract Product Classes & Concrete Subclasses ScrollBar ScrollTo(int) Button Press() Menu Pupup() MotiScrollBar ScrollTo(int) MacScrollBar ScrollTo(int) PMScrollBar ScrollTo(int) MotiButton Press() MacButton Press() PMButton Press()

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-25 PS95&96-MEF-L9-25 Dr. M.E. Fayad  Supporting Multiple Look-and-Feel: Abstract Factory Pattern Abstract Factory Pattern Factories and products are the key players in the Abstract Factory pattern. This pattern captures how to create families of related product objects without instantiating classes directly The Abstract Factory pattern’s emphasis on families of products distinguishes it from other creational patterns, which involve only one kind of product object

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-26 PS95&96-MEF-L9-26 Dr. M.E. Fayad  Supporting Multiple Window Systems Goals & Constraints Encapsulating Implementation Dependencies Window and WindowRep Design Patterns: Bridge Pattern

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-27 PS95&96-MEF-L9-27 Dr. M.E. Fayad This is another portability issue. Lexi must support multiple windows Lexi is designed to run on as many platforms as possibe for exactly the same reasons we support look-and- feel standards  Supporting Multiple Window Systems: Goals & Constraints

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-28 PS95&96-MEF-L9-28 Dr. M.E. Fayad  Supporting Multiple Window Systems: Encapsulating Dependencies glyph->Draw(this) Glyph Draw(Window) Window Redraw() Iconify() Lower() DrawLine() ApplicationWindowIconWindow Iconify() DialogWindow Lower() glyph owner->Lower()

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-29 PS95&96-MEF-L9-29 Dr. M.E. Fayad  Supporting Multiple Window Systems: Window & WindowRep WindowImp DeviceRaise() DeviceRect(...) Window Raise() DrawRect(...) ApplicationWindowIconWindow DialogWindow imp MacWindowImp DeviceRaise() DeviceRect(...) PMWindowImp DeviceRaise() DeviceRect(...) XWindowImp DeviceRaise() DeviceRect(...)

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-30 PS95&96-MEF-L9-30 Dr. M.E. Fayad  Supporting Multiple Window Systems: Bridge Pattern Bridge Pattern The relationship between Window and WindowRep is an example of the Bridge Pattern. The Bridge Pattern allows separate class hierarchies to work together even as they evolve independently. The Bridge Pattern allows for maintaining and enhancing the logical windowing abstractions without touching window system-dependent code, and vice versa.

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-31 PS95&96-MEF-L9-31 Dr. M.E. Fayad ‘ User Operations Goals & Constraints Encapsulating the Request for a Service Commands and Histories Design Patterns: Command Pattern

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-32 PS95&96-MEF-L9-32 Dr. M.E. Fayad Lexi provides different interfaces for the following operations: –Creating a new document –Opening, saving, and printing an existing document –Cutting selected text out of the document and pasting it back in –Changing the font and style of selected text –Changing the formatting of text –Quitting the application –and plus many more... Lexi’s is also designed to support undo and redo of most but not all its functionality The challenge is to come up with a simple and extensible mechanism that satisfies all of these needs ‘ User Operations: Goals and Constraints

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-33 PS95&96-MEF-L9-33 Dr. M.E. Fayad ‘ User Operations: Encapsulating the Request of a Service Command Execute() PasteCommand Execute() if (document is modified) { save->Execute() } quit the application QuitCommand Execute() SaveCommand Execute() buffer FontCommand Execute() newFont paste buffer into document make selected text appear in newFont pop up a dialog box that lets the user name the document, and then save the document under that name save Partial Command Class Hierarchy

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-34 PS95&96-MEF-L9-34 Dr. M.E. Fayad ‘ User Operations: Commands & Histories Glyph Command Execute() MenuItem Clicked() command command->Execute() MenuItem-Command Relationship

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-35 PS95&96-MEF-L9-35 Dr. M.E. Fayad A command may delegate all, part, or none of the request’s implementation to other objects This is perfect for Lexi that must provide centralized access to functionality scattered throughout the application. ‘ User Operations: Command Pattern Command Pattern The Command pattern objectifies the request for service. It decouples the creator of the request for a service from the executor of that service.

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-36 PS95&96-MEF-L9-36 Dr. M.E. Fayad ’ Spell Checking and Hyphenation Goals & Constraints Encapsulating Traversal Traversal versus Traversal Actions Design Patterns: Iterator & Visitor Pattern

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-37 PS95&96-MEF-L9-37 Dr. M.E. Fayad The design problem involves textual analysis: –Checking for misspelling –Introducing hyphenation points where needed for good formatting. Constraints are similar to the formatting constraints Two pieces of the puzzle: –Accessing the information to be analyzed –Doing the analysis ’ Spell Checking and Hyphenation: Goals and Constraints

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-38 PS95&96-MEF-L9-38 Dr. M.E. Fayad ’ Spell Checking and Hyphenation: Traversal vs. Traversal Actions Command Execute() NullIterator First() Next() IsDone() CurrentItem() iterator return true Iterator Class & Subclasses return new NullIterator ListIterator First() Next() IsDone() CurrentItem() ArrayIterator First() Next() IsDone() CurrentItem() PreorderIterator First() Next() IsDone() CurrentItem() currentItem Glyph... CreatorIterator() root

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-39 PS95&96-MEF-L9-39 Dr. M.E. Fayad Iterator Pattern Iterator Pattern objectifies traversal algorithms over object structures. Visitor Pattern Visitor Pattern centralizes operations on object structures in one class so that these operations can be changed independently of the classes defining the structure. ’ Spell Checking and Hyphenation: Iterator & Visitor Patterns

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-40 PS95&96-MEF-L9-40 Dr. M.E. Fayad Summary Eight different patterns applied in the Lexi’s design: –Composite to represent the document’s physical structure –Strategy to allow different formatting algorithms –Decorator for embellishing the user interface –Abstract factory for supporting multiple look-and-feel standards –Bridge to allow multiple windowing platforms –Command for undoable user operations –Iterator for accessing and traversaling object structures –Visitor for allowing an open-ended number of analytical capabilities without complicating the document structure’s implementation

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-41 PS95&96-MEF-L9-41 Dr. M.E. Fayad Discussion Questions 1. Define: Glyphs and Monoglyph 2. List the goals and constraints of: Formatting Support multiple look-and-feel standards User operations Embellishing the user interface 3. Explain how to achieve the goals for formatting