csse 374: more object design with gang of four design … · csse 374: more object design with gang...
TRANSCRIPT
![Page 1: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/1.jpg)
CSSE 374: More Object Design with
Gang of Four Design Patterns
Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685 Email: [email protected]
Q1
![Page 2: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/2.jpg)
Learning Outcomes: Patterns, Tradeoffs Identify criteria for the design of a software system and select patterns, create frameworks, and partition software to satisfy the inherent trade-offs.
Using GoF Patterns in Iteration 3 Local caching Failover to local services Support for third-party
POS devices Handling payments
Exercise (if time) Design Studio with Team 2.3
Q3
![Page 3: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/3.jpg)
Gang of Four Design Patterns Behavioral Interpreter Template
Method Chain of
Responsibility Command Iterator Mediator Memento Observer State Strategy Visitor
Creational Factory Abstract
Factory Builder Prototype Singleton
Structural Adapter Bridge Composite Decorator Façade Flyweight Proxy
Q1
![Page 4: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/4.jpg)
Failover & Performance with Local Caching
What is a cache? How does a cache usually work?
Why use a local cache for NextGen POS? Performance Improve recoverability
Q2
![Page 5: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/5.jpg)
Search Strategy for Product Information
1. Look in memory (in map stored by ProductCatalog)
2. Look on local hard drive cache
3. Retrieve from remote persistence service
Q3
![Page 6: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/6.jpg)
Applying the Adapter Pattern
Q4
“True” Adapters
![Page 7: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/7.jpg)
Using a Factory to Set Up for Local Caching
Q5
Eliminate local cache?
Change external data source?
:Store :Register
pc:ProductCatalog
create 2: create(pc)
1: create
1:ServicesFactory
psa : LocalProducts externalService :DBProductsAdapter
1.1: psa = getProductsAdapter()
1.1.2: create( externalService ) 1.1.1: create
the local service gets a reference to the adapter for the external service
the local service is returned
![Page 8: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/8.jpg)
Product Lookup with In-memory Miss
![Page 9: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/9.jpg)
Product Lookup with Local Cache Miss
![Page 10: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/10.jpg)
Using Threads to Freshen the Cache
Async msg
![Page 11: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/11.jpg)
How’s the final iteration going?
Used by permission. http://notinventedhe.re/on/2009-12-28
![Page 12: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/12.jpg)
Handling Failure in NextGen POS: What should happen if there is a local cache miss and the external product information service fails?
Think for 15 seconds… Turn to a neighbor and discuss
it for a minute
![Page 13: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/13.jpg)
DCD: Exceptions Caught and Thrown
PersistenceFacade
usageStatistics : Map
Object get(Key, Class) throws DBUnavailableException, FatalExceptionput(Key, Object) { exceptions= (DBUnavailableException, FatalException) }...
exceptionsFatalExceptionDBUnavailableException
exceptions thrown can be listed in another compartment labeled "exceptions"
UML: One can specify exceptions several ways.
1. The UML allows the operation syntax to be any other language, such as Java. In addition, some UML CASE tools allow display of operations explicitly in Java syntax.Thus,
Object get(Key, Class) throws DBUnavailableException, FatalException
2. The default UML syntax allows exceptions to be defined in a property string. Thus,
put(Object, id) { exceptions= (DBUnavailableException, FatalException) }
3. Some UML tools allow one to specify (in a dialog box) the exceptions that an operation throws.
![Page 14: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/14.jpg)
Showing Exception in Sequence Diagrams
Convert Exceptions pattern
Q6
Name the Problem not the Thrower
«exception»DBUnavailableException()
: DBProductsAdapter
: PersistenceFacade
UML notation: ⎠ All asynchronous messages, including exceptions, are illustrated with a stick
arrowhead.⎠ Exceptions are shown as messages indicated by the exception class name.⎠ An optional «exception» or «signal» stereotype is legal (an exception is a kind
of signal in the UML), if increased visibility is desired.
ps = get(...)
ps = getDescription(id)
: java.sql.Statement
resultSet = executeQuery(...)
«exception»SQLException()
note the difference between synchronous and asynchronous message arrowheads in the UML
recall that in UML 2, a lifeline box can use an interface type to indicate an object of some anonymous class that implements this interface
«exception»ProductInfoUnavailableException()
stopping the message line at this point indicates the PersistenceFacade object is catching the exception
![Page 15: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/15.jpg)
How should NextGen POS handle this exception?
Common exception handling patterns Use a central error logging object to record all
exceptions for diagnosis by developers
Use a standard, application-independent, non-UI object to notify users Can delegate to multiple different UI notifications Protected Variation for changes in reporting
Q7
![Page 16: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/16.jpg)
Failover to Local Services with a Proxy
![Page 17: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/17.jpg)
Proxy GoF Pattern
Problem: How do we control access to some subject object if we want to avoid giving direct access? Solution: Add a level of indirection with a proxy object that implements the same methods as the subject and conditionally delegates to it.
Q8,9
![Page 18: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/18.jpg)
Structure of the Proxy Pattern
«interface»ISubjectInterface
foo()
RealSubject
foo()
{... pre-processingrealSubject.foo()... post-processing}
Client
subject : ISubjectInterface
doBar()
1
1
Proxy
realSubject : ISubjectInterface
foo()
{... whateversubject.foo()... whatever}
subject actually references an instance of Proxy, not RealSubject
"realSubject" will actually reference an instance of RealSubject
![Page 19: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/19.jpg)
Proxy in NextGen POS
Posting sales to the accounting service Send postSale(Sale) to a redirection proxy
Proxy attempts to post to external service If it fails, then proxy stores
result locally
![Page 20: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/20.jpg)
Proxy in NextGen POS — DCD
![Page 21: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/21.jpg)
Proxy in NextGen POS: Object Diagram
![Page 22: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/22.jpg)
Exercise: Proxy for Failover
Break up into your teams
Consider how NextGen POS can use a Proxy to failover to local storage if the remote accounting service is down.
Sketch a communication diagram depicting the above situation.
![Page 23: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/23.jpg)
Design Studio Calendar
Monday Tuesday Thursday
8th week Team 2.4 Team 2.1
9th week Team 2.2 Today
Team 2.3 Team 2.5
10th week Team 2.4 Team 2.1 Course Wrap-up
![Page 24: CSSE 374: More Object Design with Gang of Four Design … · CSSE 374: More Object Design with Gang of Four Design Patterns Shawn Bohner Office: Moench Room F212 Phone: (812) 877-8685](https://reader035.vdocuments.net/reader035/viewer/2022081521/5aedbea47f8b9a585f90a846/html5/thumbnails/24.jpg)
Homework and Milestone Reminders
Read Chapter 37
Milestone 5 – Final Junior Project System and Design Preliminary Design Walkthrough on Friday, February
11th, 2011 during weekly project meeting Final due by 11:59pm on Friday, February 18th, 2011
Team 2.5 Design Studio