Lexi case study (Part 2) Presentation by Matt Deckard.

Slides:



Advertisements
Similar presentations
Java Review Interface, Casting, Generics, Iterator.
Advertisements

GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
Computer Science 313 – Advanced Programming Topics.
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.
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.
BehavioralCmpE196G1 Behavioral Patterns Chain of Responsibility (requests through a chain of candidates) Command (encapsulates a request) Interpreter (grammar.
Design Patterns David Talby. This Lecture n Patterns for a User Interface u Representing a Document F Composite, Flyweight, Decorator u Writing Portable.
Basic Design Patterns 2. Designing a Document Editor Gabriel Mañana Ed. 453 Of. 120 Ext unal.edu.co.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Command Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
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.
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.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
CS 210 Introduction to Design Patterns September 28 th, 2006.
Design a Document Editor Oksana Protsyk Yaroslav Kaplunskiy.
CSE 332: Design Patterns (Part I) Introduction to Design Patterns Design patterns were mentioned several times so far –And the Singleton Pattern was discussed.
A Case Study: Designing a Document Editor “ Lexi ”
Object Composition Interfaces Collections Covariance Object class Programming using C# LECTURE 10.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
Chapter 9: The Iterator Pattern
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VII Observer, Command, and Memento.
Data structures Abstract data types Java classes for Data structures and ADTs.
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.
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 VIII Chain of Responsibility, Strategy, State.
Stacks The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Design Patterns David Talby. This Lecture Re-routing method calls Chain of Responsibility Coding partial algorithms Template Method The Singleton Pattern.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
Behavioral Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
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.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
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.
CSE 332: Design Patterns (Part II) Last Time: Part I, Familiar Design Patterns We’ve looked at patterns related to course material –Singleton: share a.
Behavioural Patterns GoF pg Iterator GoF pg. 257 – 271 Memento GoF pg By: Dan Sibbernsen.
CSE 432: Thanks for the memory leaks, Pushme-Pullyu, and Command Summary of “Thanks for the Memory Leaks” “Left-over” design forces from Type Laundering.
The Command Pattern SE-2811 Dr. Mark L. Hornick 1.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
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.
Stacks The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
Turning method call into an object
Chapter 10 Design Patterns.
MPCS – Advanced java Programming
Case Study 1: Designing a Document Editor
Behavioral Design Patterns
Chapter-II A Case Study:
Programming Design Patterns
Design Patterns A Case Study: Designing a Document Editor
“The Trouble with Observer” and “Visitor Revisited”
PH Chapter 3 Thanks for the Memory Leaks Pushme-Pullyu (pp
The iterator and memento patterns
Structural Patterns: Adapter and Bridge
Command-Processor Pattern
Software Engineering and Architecture
Presentation transcript:

Lexi case study (Part 2) Presentation by Matt Deckard

User Operations  Support different operations  Cut, copy, paste  Formatting  Printing  Etc.  Support different Uis  Menus  Buttons  Keyboard shortcuts  Etc.

User Operations  Avoid coupling operations and UIs  Use multiple UIs for single operations  Change UIs in the future  Avoid creating dependencies to classes operations are defined in  Undo and Redo  Want some, but not all operations to be undoable  Un-undoable operations:  Saving  Creating new documents  Printing  Don’t want arbitrary limit on levels of undo

User Operations  Encapsulate user operations  GUI menus are just glyphs that perform actions in response to user interaction  Create subclass of Glyph called MenuItem  But don’t want to make each operation a subclass of MenuItem (avoid decoupling!)  Parameterize menu items by uper operations  How?

User Operations  How should user operations be parameterized?  Simple function call has drawbacks:  Doesn’t address undo/redo  Hard to associate state with function  Difficult to extend, reuse  Use objects instead  Can store state, implement undo/redo  Use inheritance to extend, reuse

Command class  Command: abstract class representing user operation  Based on abstract method Execute()  Subclasses will implement Execute() according to the operation they represent  Subclasses can delegate parts of user operation to other objects  Command objects are treated uniformly by requestor  MenuItem will store instance of Command object to encapsulate its associated user operation

Command class  Undoability  Add abstract Unexecute() method  During Execute(), Commands will store whatever information they need to undo later  Add abstract Reversible() method  Returns true if and only if this Command is undoable  Allows Commands to determine undoability at runtime  i.e. redundant or vacuous Commands shouldn’t be undoable  Command history  Need list of Commands to support multiple undos  Traverse back and forth through list to undo and redo  Call Unexecute() when undoing, Execute() when redoing

Command class

Command Pattern  Encapsulates a request (user operation)  Prescribes uniform interface for requests  Shields clients from request’s implementation  Allows delegation of request to other objects  Provides centralized access to functionality  Allows to queue or log requests  Supports undo, redo  AKA “Action”, “Transaction”  Similar to functor (but not quite the same)

Command Pattern  Related patterns  Use with Composite and you’ve got: macros!  Use with Memento to remember state (for undo)  Use Prototype to copy command before putting in undo list, to distinguish multiple invocations of same command

Spellchecking and Hyphenation  Textual analysis  Want to support multiple algorithms, addition of new ones in future  Avoid coupling to document structure  Add other types of analysis in future  i.e. search, word count, etc.  Two pieces:  Accessing information to be analyzed  Performing the analysis

Accessing scattered information  Data access  Glyphs may be stored in different ways  Need mechanism to access all of them  Traversal  Different analyses may access Glyphs in different ways (i.e. forward vs. reverse search)  Issues  Only Glyphs know their data structure  Glyph interface shouldn’t be biased toward one structure over another  i.e. using integer index biased us toward arrays  Want to provide multiple access and traversal methods

Accessing scattered information  One approach: adding methods to Glyph  void First(Traversal) – initializes specified traversal  void Next() – advances to next Glyph in traversal  bool IsDone() – reports if traversal is over  Glyph* GetCurrent() – accesses current glyph  Replaces Child()  void Insert(Glyph*) – inserts Glyph at current pos  Replaces Insert(Glyph*, int)

Accessing scattered information  Issues with this approach  Must extend Traversal enumeration to support new traversals  Would also have to change lots of subclasses  Difficult to reuse mechanism for other object structures  Doesn’t support multiple traversals in parallel

Iterator class  Better approach: encapsulate access and traversal  Iterator  Abstract class  Defines interface for access and traversal  Subclass contains reference to structure it traverses  CreateIterator()  By default, will return NullIterator  Subclasses can override, based on their structure  Iterators can use CreateIterator() on their root glyphs to support different traversal

Iterator class  Example: PreorderIterator  First()  Calls CreateIterator() on root  Calls First() on returned Iterator  Pushes Iterator onto stack  CurrentItem()  Calls CurrentItem() on Iterator at top of stack  Returns result  Next()  Calls CreateIterator() on top Iterator  Calls First() on returned Iterator  Pushes Iterator onto stack  Calls IsDone() on latest Iterator. If true, pops it off and repeats

Iterator class

Iterator Pattern  Abstracts traversal algorithm  Shields clients from internal structure of objects traversed  Gain flexability, usability  Easy to extend  Easy to reuse by parameterizing object type  Can perform multiple traversals in parallel

Performing the analysis  Want to distinguish analysis from traversal  Flexibility, reusability  Different analyses might require same traversal  Want to distinguish different types of glyphs  Different analyses consider different glyphs  Could abstract in Glyph, have subclasses implement  Drawbacks to this approach:  Have to change multiple subclasses  Obscures basic glyph interface

Performing the analysis  Encapsulate the analysis  Create analysis classes  For now, let’s consider a SpellChecker class  Iterator has instance of SpellChecker  Uses SpellChecker instance as it traverses  SpellChecker accumulates information as it is used

Performing the analysis  How to distinguish glyphs?  SpellChecker treats different glyph types differently  Don’t want to resort to type tests or casting (gross)  Instead, have the glyph object tell SpellChecker to check it  Glyph has abstract CheckMe() method  SpellChecker has methods for every glyph subclass, i.e. CheckCharacter(), CheckRow(), CheckImage(), etc.  Glyph sublcasses will override CheckMe() to call the appropriate method in SpellChecker

Performing the analysis

 Adding new analyzers  Will be difficult if we define them as separate classes  Instead, abstract it as a Visitor class  CheckMe() becomes the Accept() method  Takes any Visitor as parameter, so don’t have to touch glyph subclasses when adding new analyzers  CheckCharacter(), etc become the Visit() method  Overloaded, takes visited subclass as parameter  Need one for every subclass that implements Accept()

Visitor Pattern  Can be applied to any object structure  Visitees needn’t have common parent class  Tradeoff:  When you add Visitors you don’t have to update object structure, BUT:  When you add subclasses to object structure, you DO have to update your Visitor classes  Sometimes can provide default “do nothing” operation in Visitor  Helps avoid “polluting” classes with many operations  Helps to separate groups of common operations  Can accumulate state as they visit elements  Sometimes compromises encapsulation of visitee  elements

Summary  Needed to support different user operations  Encapsulate the concept that varies (Command)  Needed to support different methods of accessing and traversing data  Encapsulate the concept that varies (Iterator)  Needed to support different analysis algorithms  Encapsulate the concept that varies (Visitor)  (Are we seeing a pattern here?)