GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.

Slides:



Advertisements
Similar presentations
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Advertisements

[Course Title] [Module Title]
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Iterators T.J. Niglio Computer & Systems Engineering Fall 2003 Software Design & Documentation Object Behavioral.
Design Patterns In OPM Presented by: Galia Shlezinger Instructors: Prop. Dov Dori, Dr. Iris Berger.
Software Design & Documentation – Design Pattern: Command Design Pattern: Command Christopher Lacey September 15, 2003.
GoF: Document Editor Example
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.
Basic Design Patterns 2. Designing a Document Editor Gabriel Mañana Ed. 453 Of. 120 Ext unal.edu.co.
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Document Editor - Page L2-5 PS95&96-MEF-L9-5 Dr. M.E. Fayad  Document Structure.
Lecture 4: More UML Diagrams, Patterns MISM/MSIT Fall 2001.
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.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Design Patterns.
Prof. Aiken CS 169 Lecture 51 Design Patterns CS169 Lecture 5.
1 GoF Template Method (pp ) GoF Strategy (pp ) PH Single User Protection (pp ) Presentation by Julie Betlach 6/08/2009.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
More Design Patterns In Delphi Jim Cooper Falafel Software Session Code: D3.03 Track: Delphi.
Design a Document Editor Oksana Protsyk Yaroslav Kaplunskiy.
A Case Study: Designing a Document Editor “ Lexi ”
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
Lexi case study (Part 2) Presentation by Matt Deckard.
GoF Sections Design Problems and Design Patterns.
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.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
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
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Command Pattern.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
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.
CS 4233 Review Feb February Review2 Outline  Previous Business – My.wpi.edu contains all grades to date for course – Review and contact.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
Design Patterns Introduction
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
CS212: Object Oriented Analysis and Design Lecture 39: Design Pattern-III.
Interface Patterns. Adapter Provides the interface a client expects, using the services of a class with a different interface Note Avoid using object.
Advanced Object-oriented Design Patterns Creational Design Patterns.
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.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
Behavioural Patterns GoF pg Iterator GoF pg. 257 – 271 Memento GoF pg By: Dan Sibbernsen.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
Design Patterns. Outline Purpose Purpose Useful Definitions Useful Definitions Pattern Overview Pattern Overview.
Overview of Behavioral Patterns ©SoftMoore ConsultingSlide 1.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Chapter 10 Design Patterns.
Case Study 1: Designing a Document Editor
Behavioral Design Patterns
Chapter-II A Case Study:
More Design Patterns 1.
Design Patterns Satya Puvvada Satya Puvvada.
Design Patterns A Case Study: Designing a Document Editor
Informatics 122 Software Design II
Chapter 9 Behavioral Design Patterns
PH Chapter 3 Thanks for the Memory Leaks Pushme-Pullyu (pp
A Case Study: Designing a Document Editor
The iterator and memento patterns
Design Patterns Difficult to describe abstractly Elements:
Informatics 122 Software Design II
Presentation transcript:

GoF Sections 2.7 – 2.9 More Fun with Lexi

Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface  Supporting multiple look-and-feel standards  Supporting multiple window systems

Lexi Document Editor Lexi tasks remaining:  User Operations  Spell checking and hyphenation

User Operations Large variety in functionality  Create a new document  Cut and Paste selected document text  Change the font of selected text  Change the format of selected text  Change alignment and justification  Quit application  Etc.

User Operations Different user interfaces for these operations Want to avoid coupling particular user operation with a particular user interface  Could use multiple user interfaces for same operation  May want to change the interface in the future Theses operation are implemented in different classes. We want to access their functionality without creating a lot of dependencies (avoid tight coupling) Want ability to undo/redo (some) operations  Can’t undo quitting the application  Should be no limit on number of levels available

User Operations So how do we handle these? Treat a pull-down menu as a type of glyph ( The difference with other composite glyphs is that they do some work when they are clicked on)  Subclass Glyph with MenuItem (special glyphs that do some operations) One possible approach  Have a subclass of MenuItem for each type of user operation and hard code each subclass to handle each request Does this work?  Couples the request to a particular user interface

User Operations Approach 2: Give MenuItem class a function to call to perform the operation Gives more run-time flexibility Does it suit Lexi’s needs?  Doesn’t address undo/redo problem  Difficult to associate state with a function  Functions are difficult to extend

User Operations A better way Parameterize MenuItems with a Command object Addresses the 3 issues just discussed  Undo/redo  Store state  Extend through inheritance

User Operations

Can use Command to handle Undo/Redo Add Unexecute function to Command interface Use a command history list

. Cmd1Cmd2Cmd3Cmd4 Present FuturePast

User Operations The Command Pattern (GoF, pg 233) Intent:  Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations

Spell Check & Hyphenation Lexi needs ability to spell check and improve formatting Constraints  Need to support multiple algorithms  Should be easy to add new algorithms  Should be able to add new kinds of analyses Searching Word Counting Grammar Check

Spell Check & Hyphenation 2 main pieces to address  How to access the information to be analyzed  How to do the actual analysis

Spell Check & Hyphenation Accessing the information Data is scattered in the Glyph objects Problems  Glyphs can store children in multiple ways linked list, arrays, etc  Not all traversals will be beginning to end Must allow differing data structures Must support differing traversals

Spell Check & Hyphenation Put the traversal operations in the glyph classes? Encapsulate the concept that varies: The access and traversal mechanisms Have Iterator classes do the work

Spell Check & Hyphenation Abstract Iterator class w/ general interface First( ), Next( ), IsDone( ), CurrentItem( )

Subclasses ArrayIterator, ListIterator, PreorderIterator, PostorderIterator Implement the access and traversals Subclass contains reference to the structure it will traverse CreateIterator( ) added to Glyph interface

Spell Check & Hyphenation The Iterator Pattern (GoF, pg 257) Intent:  Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation

Spell Check & Hyphenation Now, how do we analyze the data accessed? We can put the analysis in the Iterator classes Will this work?

Spell Check & Hyphenation Want to keep analysis separate from the traversal Also need to be able to distinguish between different glyph types Solution:  Encapsulate the analysis in an object

But where to put this object? - One solution is to add analysis ability to the Glyph. For each analysis we can add a one or more abstract operations to the Glyph class. Problem: We need to change glyph class whenever we add a new kind of analysis. Other problem: Glyph interfaces grow over time and deviates from the initial purpose

Spell Check & Hyphenation Use the analysis object in conjunction with the iterator Iterator brings the object along to analyze as it traverses the glyphs Analyzer gathers pertinent info as the traversal proceeds

The fundamental question with this approach is how the analysis object distinguishes different kinds of glyphs without resorting to type tests or downcasts. We don't want a SpellingChecker class to include ugly (pseudo)code like: void SpellingChecker::Check (Glyph* glyph) { Character* c; Row* r; Image* i; if (c = dynamic_cast (glyph)) { // analyze the character } else if (r = dynamic_cast (glyph)) { // prepare to analyze r's children } else if (i = dynamic_cast (glyph)) { // do nothing }

Spell Check & Hyphenation Define the abstract Visitor class for performing the analysis Contains Visit_____ ( ) operations for each glyph subclass Concrete subclasses include SpellingCheckerVisitor and Hyphenation Visitor Add an abstract CheckMe( Visitor& ) operation to the Glyph class  Eliminates need for analyzer to type check each glyph it encounters

So Let’s add the following abstract operation to the Glyph class: void CheckMe(SpellingChecker&) We define CheckMe in every Glyph subclass as follows: void GlyphSubclass::CheckMe (SpellingChecker& checker) { checker.CheckGlyphSubclass(this); } Where CheckGlyphsubclass is replaced by the glyph subclass name as follows:

class SpellingChecker { public: SpellingChecker(); virtual void CheckCharacter(Character*); virtual void CheckRow(Row*); virtual void CheckImage(Image*); //... and so forth List & GetMisspellings(); protected: virtual bool IsMisspelled(const char*); private: char _currentWord[MAX_WORD_SIZE]; List _misspellings; };

Now we can traverse the glyph structure, calling CheckMe on each glyph with the spelling checker as an argument. This effectively identifies each glyph to the SpellingChecker and prompts the checker to do the next increment in the spelling check. SpellingChecker spellingChecker; Composition* c; //... Glyph* g; PreorderIterator i(c); for (i.First(); !i.IsDone(); i.Next()) { g = i.CurrentItem(); g->CheckMe(spellingChecker); }

Spell Check & Hyphenation The Visitor Pattern (GoF, pg 331) Intent:  Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.

Spell Check & Hyphenation What happens to our Visitor class if a new Glyph subclass is added? Forced to update all Visitor classes with a new VisitNewGlyph( ) operation Therefore, best to use Visitor if you’re sure the objects you’re working on (in this case Glyphs) have a stable class structure

Lexi Summary Composite  Represent the documents physical structure Strategy  Allow different formatting algorithms Decorator  Embellish the user interface Abstract Factory  Support multiple look-and-feel standards

Lexi Pattern Summary Bridge  Allow multiple windowing platforms Command  Undoable user operations Iterator  Accessing and traversing object structures Visitor  Allow open-ended number of analytical tasks

Lexi Pattern Summary Worth noting, these patterns are not limited to the Lexi program The patterns are (easily) adapted to many other common designs  Decorator and Command used in Lexi as they would in any typical application with a GUI