SlideShare a Scribd company logo
1 of 37
Design Pattern
“A case study: Designing a document editor”
1
Contents
• Introduction to Lexi features
• Design problems
• Spelling Checking & Hyphenation
• Solution: Encapsulate Traversal
• Conclusion
2
Introduction to Lexi Features
• WYSIWYG Document Editor
• Mix text and graphics in a variety of styles
• Pull-down Menus
• Scrollbars
• Icons for jumping to a particular page
3
4
Design Problems
1. Document Structure
2. Formatting
3. Embellishing the user interface
4. Supporting multiple look-and-feel standards
5. Supporting multiple window systems
6. User Operations
5
Document Structure
• Goals:
–present document’s visual aspects
–drawing, hit detection, alignment
–support physical structure
(e.g., lines, columns)
• Constraints/forces:
–treat text & graphics uniformly
–no distinction between one & many
6
• Some constraints:
– we should treat text and graphics uniformly
– our implementation shouldn’t have to
distinguish between single elements and
groups of elements in the internal
representation
• Recursive Composition:
– a common way to represent hierarchically
structured information
7
8
• Glyphs:
– an abstract class for all objects that can appear
in a document structure
– three basic responsibilities, they know
• how to draw themselves, what space they
occupy, and their children and parent
• Composite Pattern:
– captures the essence of recursive composition
in object-oriented terms
9
10
11
Formatting
• A structure that corresponds to a properly formatted
document
• 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
• “Formatting” mean breaking a collection of glyphs in to
lines
• Encapsulating the formatting algorithm
– keep formatting algorithms completely independent
of the document structure
– make it is easy to change the formatting algorithm
– We’ll define a separate class hierarchy for objects that
encapsulate formatting algorithm
12
• Compositor and Composition:
– We’ll define a Compositor class for objects
that can encapsulate a formatting algorithm
– The glyphs Compositor formats are the
children of a special Glyph subclass called
Composition
– When the composition needs formatting, it
calls its compositor’s Compose operation
– Each Compositor subclass can implement a
different line breaking algorithm
• 13
14
15
Embellishing the User Interface
• Considering adds a border around the text
editing area and scrollbars that let the user view
the different parts of the page here
• Transparent Enclosure
– object composition
• Border and Scroller should be a subclass of Glyph
– two notions
• single-child (single-component) composition
• compatible interfaces
16
• Monoglyph:
– We can apply the concept of transparent enclosure to
all glyphs that embellish other glyphs
– the class, Monoglyph
• Decorator Pattern:
– captures class and object relationships that support
embellishment by transparent enclosure
17
18
Supporting Multiple
Look-and-Feel Standards
• Design to support the look-and-feel changing at
run-time
• Abstracting Object Creation:
– widgets
– two sets of widget glyph classes for this purpose
– Lexi needs a way to determine the look-and-feel
standard being targeted
– We must avoid making explicit constructor calls
– We must also be able to replace an entire widget set
easily
– We can achieve both by abstracting the process of
object creation
19
• Factories and Product Classes
– Factories create product objects
– The example
• Abstract Factory Pattern
– capture how to create families of related product
objects without instantiating classes directly
20
21
22
Supporting Multiple Window
Systems
• Lexi to run on many existing window systems
having different programming interfaces
• Encapsulating Implementation Dependencies
– The Window class interface encapsulates the
things windows tend to do across window
systems
– The Window class is an abstract class
• Window and WindowImp
• Bridge Pattern
– to allow separate class hierarchies to work together
even as they evolve independently 23
24
25
26
User Operations
• Requirements:
– Lexi provides different user interfaces for the operations it
supported
– These operations are implemented in many different classes
– Lexi supports undo and redo
• The challenge is to come up with a simple and
extensible mechanism that satisfies all of these
needs
• Encapsulating a Request:
– We could parameterize MenuItem with a function to call, but
that’s not a complete solution
– We should parameterize MenuItems with an object, not a
function
27
• Command Class and Subclasses:
– The Command abstract class consists of a single abstract
operation called “Execute”
– MenuItem can store a Command object that encapsulates a
request
– When a user choose a particular menu item, the MenuItem
simply calls Execute on its Command object to carry out
the request
28
29
30
• Undoability:
– To undo and redo commands, we add an
Unexecute operation to Command’s interface
– A concrete Command would store the state of the
Command for Unexecute
– Reversible operation returns a Boolean value to
determine if a command is undoable
• Command History:
– a list of commands that have been executed
present
past commands
31
Spelling Checking &
Hyphenation
• Goals:
– analyze text for spelling errors
– introduce potential hyphenation sites
• Constraints/forces:
– support multiple algorithms
– don’t tightly couple algorithms with document
structure
32
Solution: Encapsulate Traversal
• Iterator
– encapsulates a traversal algorithm without exposing
representation details to callers
– uses Glyph’s child enumeration operation
– This is an example of a “preorder iterator”
• Intent
– access elements of a container without exposing its representation
• Applicability
– require multiple traversal algorithms over a container
– require a uniform traversal interface over different containers
– when container classes & traversal algorithm must vary independently
33
Structure
34
• Consequences:
+flexibility: aggregate & traversal are independent
+multiple iterators & multiple traversal algorithms
– additional communication overhead between iterator &
aggregate
• Implementation:
– internal versus external iterators
– violating the object structure’s encapsulation
– robust iterators
– synchronization overhead in multi-threaded programs
– batching in distributed & concurrent programs
• Known Uses:
– C++ STL iterators
– JDK Enumeration, Iterator
– Unidraw Iterator
35
Conclusion
• design reuse
• uniform design vocabulary
• understanding, restructuring, & team
communication
• provides the basis for automation
• a “new” way to think about design
36
Patterns
• Composite: to represent the document's physical structure,
• Strategy: to allow differentformatting algorithms,
• Decorator: for embellishingthe user interface,
• Abstract Factory: forsupporting multiple look-and-feel
standards,
• Bridge: to allow multiplewindowing platforms,
• Command: for undoable useroperations,
• Iterator: for accessing andtraversing object structures, and
• Visitor: for allowing anopen-ended number of analytical
capabilities without complicatingthe document structure's
implementation.
37

More Related Content

Similar to Design patterns

Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"LogeekNightUkraine
 
Design patterns Structural
Design patterns StructuralDesign patterns Structural
Design patterns StructuralUMAR ALI
 
Software Engineering Lec 8-design-
Software Engineering Lec 8-design-Software Engineering Lec 8-design-
Software Engineering Lec 8-design-Taymoor Nazmy
 
Data Structure and Algorithms
Data Structure and AlgorithmsData Structure and Algorithms
Data Structure and Algorithmsiqbalphy1
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptRushikeshChikane1
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptRushikeshChikane2
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxanguraju1
 
Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Hemlathadhevi Annadhurai
 
Drupal case study: Behind the scenes of website of University of Tartu
Drupal case study: Behind the scenes of website of University of TartuDrupal case study: Behind the scenes of website of University of Tartu
Drupal case study: Behind the scenes of website of University of TartuRené Lasseron
 
Marco Mancuso - Data Context Interaction
Marco Mancuso - Data Context InteractionMarco Mancuso - Data Context Interaction
Marco Mancuso - Data Context InteractioncosenzaLab
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSergey Aganezov
 
Contentful with Netgen Layouts workshop
Contentful with Netgen Layouts workshopContentful with Netgen Layouts workshop
Contentful with Netgen Layouts workshopIvo Lukac
 
Asp 1-mvc introduction
Asp 1-mvc introductionAsp 1-mvc introduction
Asp 1-mvc introductionFajar Baskoro
 
Benefits of using software design patterns and when to use design pattern
Benefits of using software design patterns and when to use design patternBenefits of using software design patterns and when to use design pattern
Benefits of using software design patterns and when to use design patternBeroza Paul
 

Similar to Design patterns (20)

Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"
 
Design patterns Structural
Design patterns StructuralDesign patterns Structural
Design patterns Structural
 
Design Patterns - GOF
Design Patterns - GOFDesign Patterns - GOF
Design Patterns - GOF
 
AngularJS
AngularJSAngularJS
AngularJS
 
Design patterns-sav
Design patterns-savDesign patterns-sav
Design patterns-sav
 
Real-Time Design Patterns
Real-Time Design PatternsReal-Time Design Patterns
Real-Time Design Patterns
 
Software Engineering Lec 8-design-
Software Engineering Lec 8-design-Software Engineering Lec 8-design-
Software Engineering Lec 8-design-
 
Data Structure and Algorithms
Data Structure and AlgorithmsData Structure and Algorithms
Data Structure and Algorithms
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
 
Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Introducing object oriented programming (oop)
Introducing object oriented programming (oop)
 
Drupal case study: Behind the scenes of website of University of Tartu
Drupal case study: Behind the scenes of website of University of TartuDrupal case study: Behind the scenes of website of University of Tartu
Drupal case study: Behind the scenes of website of University of Tartu
 
Marco Mancuso - Data Context Interaction
Marco Mancuso - Data Context InteractionMarco Mancuso - Data Context Interaction
Marco Mancuso - Data Context Interaction
 
Patterns
PatternsPatterns
Patterns
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
 
Contentful with Netgen Layouts workshop
Contentful with Netgen Layouts workshopContentful with Netgen Layouts workshop
Contentful with Netgen Layouts workshop
 
Asp 1-mvc introduction
Asp 1-mvc introductionAsp 1-mvc introduction
Asp 1-mvc introduction
 
Benefits of using software design patterns and when to use design pattern
Benefits of using software design patterns and when to use design patternBenefits of using software design patterns and when to use design pattern
Benefits of using software design patterns and when to use design pattern
 
General oop concept
General oop conceptGeneral oop concept
General oop concept
 

More from Ahmed Kamel Taha (19)

Beyond vegetarianism
Beyond vegetarianismBeyond vegetarianism
Beyond vegetarianism
 
5 spy devices
5 spy devices5 spy devices
5 spy devices
 
5 spy software
5 spy software5 spy software
5 spy software
 
PRINCIPLES OF SOFTWARE ARCHITECTURE
PRINCIPLES OF SOFTWARE ARCHITECTUREPRINCIPLES OF SOFTWARE ARCHITECTURE
PRINCIPLES OF SOFTWARE ARCHITECTURE
 
Owasp & php
Owasp & phpOwasp & php
Owasp & php
 
Exam quistions
Exam quistionsExam quistions
Exam quistions
 
Questions
QuestionsQuestions
Questions
 
Choices
ChoicesChoices
Choices
 
Atm
AtmAtm
Atm
 
Software Requirements (3rd Edition) summary
Software Requirements (3rd Edition) summarySoftware Requirements (3rd Edition) summary
Software Requirements (3rd Edition) summary
 
Distributed voting system
Distributed voting systemDistributed voting system
Distributed voting system
 
Owasp & php
Owasp & phpOwasp & php
Owasp & php
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programming
 
Tcp congestion avoidance
Tcp congestion avoidanceTcp congestion avoidance
Tcp congestion avoidance
 
Offline db
Offline dbOffline db
Offline db
 
Secure mobile payment
Secure mobile paymentSecure mobile payment
Secure mobile payment
 
Mining apps for anomalies
Mining apps for anomaliesMining apps for anomalies
Mining apps for anomalies
 
Week 6 planning
Week 6 planningWeek 6 planning
Week 6 planning
 
[Software Requirements] Chapter 20: Agile Projects
[Software Requirements] Chapter 20: Agile Projects [Software Requirements] Chapter 20: Agile Projects
[Software Requirements] Chapter 20: Agile Projects
 

Recently uploaded

The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?Watsoo Telematics
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 

Recently uploaded (20)

The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 

Design patterns

  • 1. Design Pattern “A case study: Designing a document editor” 1
  • 2. Contents • Introduction to Lexi features • Design problems • Spelling Checking & Hyphenation • Solution: Encapsulate Traversal • Conclusion 2
  • 3. Introduction to Lexi Features • WYSIWYG Document Editor • Mix text and graphics in a variety of styles • Pull-down Menus • Scrollbars • Icons for jumping to a particular page 3
  • 4. 4
  • 5. Design Problems 1. Document Structure 2. Formatting 3. Embellishing the user interface 4. Supporting multiple look-and-feel standards 5. Supporting multiple window systems 6. User Operations 5
  • 6. Document Structure • Goals: –present document’s visual aspects –drawing, hit detection, alignment –support physical structure (e.g., lines, columns) • Constraints/forces: –treat text & graphics uniformly –no distinction between one & many 6
  • 7. • Some constraints: – we should treat text and graphics uniformly – our implementation shouldn’t have to distinguish between single elements and groups of elements in the internal representation • Recursive Composition: – a common way to represent hierarchically structured information 7
  • 8. 8
  • 9. • Glyphs: – an abstract class for all objects that can appear in a document structure – three basic responsibilities, they know • how to draw themselves, what space they occupy, and their children and parent • Composite Pattern: – captures the essence of recursive composition in object-oriented terms 9
  • 10. 10
  • 11. 11
  • 12. Formatting • A structure that corresponds to a properly formatted document • 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 • “Formatting” mean breaking a collection of glyphs in to lines • Encapsulating the formatting algorithm – keep formatting algorithms completely independent of the document structure – make it is easy to change the formatting algorithm – We’ll define a separate class hierarchy for objects that encapsulate formatting algorithm 12
  • 13. • Compositor and Composition: – We’ll define a Compositor class for objects that can encapsulate a formatting algorithm – The glyphs Compositor formats are the children of a special Glyph subclass called Composition – When the composition needs formatting, it calls its compositor’s Compose operation – Each Compositor subclass can implement a different line breaking algorithm • 13
  • 14. 14
  • 15. 15
  • 16. Embellishing the User Interface • Considering adds a border around the text editing area and scrollbars that let the user view the different parts of the page here • Transparent Enclosure – object composition • Border and Scroller should be a subclass of Glyph – two notions • single-child (single-component) composition • compatible interfaces 16
  • 17. • Monoglyph: – We can apply the concept of transparent enclosure to all glyphs that embellish other glyphs – the class, Monoglyph • Decorator Pattern: – captures class and object relationships that support embellishment by transparent enclosure 17
  • 18. 18
  • 19. Supporting Multiple Look-and-Feel Standards • Design to support the look-and-feel changing at run-time • Abstracting Object Creation: – widgets – two sets of widget glyph classes for this purpose – Lexi needs a way to determine the look-and-feel standard being targeted – We must avoid making explicit constructor calls – We must also be able to replace an entire widget set easily – We can achieve both by abstracting the process of object creation 19
  • 20. • Factories and Product Classes – Factories create product objects – The example • Abstract Factory Pattern – capture how to create families of related product objects without instantiating classes directly 20
  • 21. 21
  • 22. 22
  • 23. Supporting Multiple Window Systems • Lexi to run on many existing window systems having different programming interfaces • Encapsulating Implementation Dependencies – The Window class interface encapsulates the things windows tend to do across window systems – The Window class is an abstract class • Window and WindowImp • Bridge Pattern – to allow separate class hierarchies to work together even as they evolve independently 23
  • 24. 24
  • 25. 25
  • 26. 26
  • 27. User Operations • Requirements: – Lexi provides different user interfaces for the operations it supported – These operations are implemented in many different classes – Lexi supports undo and redo • The challenge is to come up with a simple and extensible mechanism that satisfies all of these needs • Encapsulating a Request: – We could parameterize MenuItem with a function to call, but that’s not a complete solution – We should parameterize MenuItems with an object, not a function 27
  • 28. • Command Class and Subclasses: – The Command abstract class consists of a single abstract operation called “Execute” – MenuItem can store a Command object that encapsulates a request – When a user choose a particular menu item, the MenuItem simply calls Execute on its Command object to carry out the request 28
  • 29. 29
  • 30. 30
  • 31. • Undoability: – To undo and redo commands, we add an Unexecute operation to Command’s interface – A concrete Command would store the state of the Command for Unexecute – Reversible operation returns a Boolean value to determine if a command is undoable • Command History: – a list of commands that have been executed present past commands 31
  • 32. Spelling Checking & Hyphenation • Goals: – analyze text for spelling errors – introduce potential hyphenation sites • Constraints/forces: – support multiple algorithms – don’t tightly couple algorithms with document structure 32
  • 33. Solution: Encapsulate Traversal • Iterator – encapsulates a traversal algorithm without exposing representation details to callers – uses Glyph’s child enumeration operation – This is an example of a “preorder iterator” • Intent – access elements of a container without exposing its representation • Applicability – require multiple traversal algorithms over a container – require a uniform traversal interface over different containers – when container classes & traversal algorithm must vary independently 33
  • 35. • Consequences: +flexibility: aggregate & traversal are independent +multiple iterators & multiple traversal algorithms – additional communication overhead between iterator & aggregate • Implementation: – internal versus external iterators – violating the object structure’s encapsulation – robust iterators – synchronization overhead in multi-threaded programs – batching in distributed & concurrent programs • Known Uses: – C++ STL iterators – JDK Enumeration, Iterator – Unidraw Iterator 35
  • 36. Conclusion • design reuse • uniform design vocabulary • understanding, restructuring, & team communication • provides the basis for automation • a “new” way to think about design 36
  • 37. Patterns • Composite: to represent the document's physical structure, • Strategy: to allow differentformatting algorithms, • Decorator: for embellishingthe user interface, • Abstract Factory: forsupporting multiple look-and-feel standards, • Bridge: to allow multiplewindowing platforms, • Command: for undoable useroperations, • Iterator: for accessing andtraversing object structures, and • Visitor: for allowing anopen-ended number of analytical capabilities without complicatingthe document structure's implementation. 37