Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 36 More Object Design with GoF Patterns 1CS6359 Fall 2011 John Cole.

Similar presentations


Presentation on theme: "Chapter 36 More Object Design with GoF Patterns 1CS6359 Fall 2011 John Cole."— Presentation transcript:

1 Chapter 36 More Object Design with GoF Patterns 1CS6359 Fall 2011 John Cole

2 NextGen POS Requirements Failover to a local service when a remote service fails Local caching Support for third-party POS devices Handling credit, debit, and check payments (and cash) CS6359 Fall 2011 John Cole2

3 Local Caching Some database elements and other data can be persisted locally such that if the service that provides them isn’t available, you have some (limited) functionality For example, if the ProductDescription database is offline, the most frequently- purchased products can be found in a file on a local disk CS6359 Fall 2011 John Cole3

4 Levels of Cache In-memory caching can keep some fixed number of elements. Sometimes this may be then entire list. Local hard-drive caching could limit by file size rather than number. (How would you organize this?) Which patterns does this use so far? Adapter and Factory CS6359 Fall 2011 John Cole4

5 Caching Strategies Lazy initialization: Fill the in-memory cache and LocalProducts file as external product info is retrieved Eager initialization loads them during start-up Cache can go stale quickly; it should be refreshed occasionally if possible. Prices can change quickly CS6359 Fall 2011 John Cole5

6 Caching and Threads One way to solve the stale cache problem is to have a thread wake up and check for updates. (What is another way, using a GoF pattern?) CS6359 Fall 2011 John Cole6

7 Dealing With Failure In the example, suppose an item is not in the local cache and the external service is offline. You could ask for a description and price, or cancel the entry. CS6359 Fall 2011 John Cole7

8 Terminology Fault: The ultimate origin or cause of misbehavior Error: Manifestation of the fault in the running system Failure: Denial of services caused by an error CS6359 Fall 2011 John Cole8

9 Throwing Exceptions Exceptions are appropriate when dealing with resource failures and other external services Where to handle the exception? CS6359 Fall 2011 John Cole9

10 Pattern: Convert Exception Avoid showing lower-level exceptions coming from lower-level services Convert a lower-level exception to one that is meaningful at the level of the subsystem. Higher level exception usually wraps the lower-level exception and adds information to make it meaningful to the higher level No one but a programmer wants to see a stack trace CS6359 Fall 2011 John Cole10

11 Pattern: Name the Problem Assign a name that describes why the exception is being thrown, not the thrower. For example, “File not found” or “Duplicate key” CS6359 Fall 2011 John Cole11

12 Exceptions in UML CS6359 Fall 2011 John Cole12 UML allows the operation syntax to be in any language, such as Java: Object get(key, class) throws DBUnavailableException, FatalException Default syntax allows exceptions to be defined in a property string Exception is a specialization of Signal, which is the specification of asynchronous communication between objects. Exception handling in UML is rarely used.

13 Exceptions in UML PersistenceFacade usageStatistics : Map Object get(Key, Class) throws DBUnavailableException, FatalException Put(Key, Object) {Exceptions=(DBUnavailableException, FatalException)} Exceptions FatalException DBUnavailableException CS6359 Fall 2011 John Cole13

14 Error Handling Pattern: Centralized Logging Use a Singleton-accessed central error logging object and report all exceptions to it. In a distributed system, each local singleton will collaborate with a central error logger Gives consistency in reporting Flexible definition of output strams and formats Also known as Diagnostic Logger CS6359 Fall 2011 John Cole14

15 Pattern: Error Dialog Standard Singleton-accessed application- independent, non-UI object to notify users of errors. It wraps one or more UI “dialog” objects and delegates notification to them. This lets you generalize and output errors as a modal dialog, sound, calling a cell phone, etc. CS6359 Fall 2011 John Cole15

16 Benefits of Error Dialog Protected Variations with respect to output mechanism Consistent style of reporting Centralized control of common strategy for error notification Minor performance gain In simple programs, you probably don’t need to use this CS6359 Fall 2011 John Cole16

17 Failover with a Proxy Sometimes the remote service should be tried first, then the local service (why?) In Java RMI and CORBA, a local client-side object is called to access a remote object’s services. This “stub” is a local proxy or representative for a remote object CS6359 Fall 2011 John Cole17

18 Proxy Problem: Direct access to a real subject object is not possible Solution: add a level of indirection, as described below Proxy is an object that implements the same interface as the subject object, holds a reference to the real subject, and controls access to it CS6359 Fall 2011 John Cole18

19 Proxy in NextGen Send a postSale message to the proxy, as though it were the actual accounting interface If the proxy cannot connect to the service (via its adapter) it redirects the message to a local service, which stores it locally until the remote service is available Diagram on P. 594 CS6359 Fall 2011 John Cole19

20 CS6359 Fall 2011 John Cole20


Download ppt "Chapter 36 More Object Design with GoF Patterns 1CS6359 Fall 2011 John Cole."

Similar presentations


Ads by Google