CSSE374 Iteration 3: More Object Design with GoF Patterns PowerPoint PPT Presentation

presentation player overlay
1 / 16
About This Presentation
Transcript and Presenter's Notes

Title: CSSE374 Iteration 3: More Object Design with GoF Patterns


1
Below Pattern-making is an old art. This is
Batik, which is a national art form in Indonesia.
From http//en.wikipedia.org/wiki/Batik.
CSSE374 Iteration 3 More Object Design with
GoF Patterns
Steve Chenoweth Day 33, Feb 6, 2009
2
Today coming up
  • Today
  • More Object Des with GoF patterns (Ch 36) ?
  • Revisit what you think you can deliver in P6?
  • Monday, Feb 9
  • HW 8 applying these ideas to your project
  • Persistence frameworks (Ch 37)
  • Tuesday, Feb 10
  • UML deployment components (Ch 38)
  • Thursday, Feb 12
  • P6 due!
  • Documenting archs (Ch 39)
  • Friday, Feb 13
  • P6A Turn in doc describing lessons learned from
    project
  • More on iterative agile (Ch 40)

3
More Object Des with GoF patterns
  • This is not all the GoF patterns. ?
  • Big application focus in this Ch is error
    handling.
  • In NextGen POS
  • Failover to a local service when a remote service
    fails
  • Local caching
  • Support for third-party POS devices, such as
    different scanners
  • Handling credit, debit, and check payments
  • Note the overall idea that designing these things
    has been deferred to Iteration 3!

Ch 36
4
Heres the whole GoF list
  • Creational Patterns
  • Abstract Factory
  • Builder
  • Factory Method
  • Prototype
  • Singleton
  • Structural Patterns
  • Adapter
  • Bridge
  • Composite
  • Decorator
  • Facade
  • Flyweight
  • Proxy
  • Behavioral Patterns
  • Chain of Responsibility
  • Command
  • Interpreter
  • Iterator
  • Mediator
  • Memento
  • Observer
  • State
  • Strategy
  • Template Method
  • Visitor

Ones we did / will do are in red.
5
NextGen POS Error Handling
  • Typical tough situation remote service failure
    how to avoid closing the store!
  • E.g., were using a remote product database, and
    the connection is interrupted.
  • Similarly for tax calculation, inventory, credit
  • What would you do to prevent these situations
    from being catastrophic? (Quiz question 1)

6
Lets analyze the books solution
  • The ServicesFactory will always return an adapter
    to a local product information service.
  • The local products adapter is not really an
    adapter to another component. It will itself
    implement the responsibilities of the local
    service.
  • The local service is initiated to a reference to
    a second adapter to the true remote product
    service.
  • If the local service finds the data in its cache,
    it returns it otherwise, it forwards the request
    to the adapter for the external service.
  • The local cache is actually 2 levels in-memory
    and on-disk.

7
Adapters for product information
How would you handle the stale cache problem?
(Quiz question 2)
8
Advantages / disadv of local cache
  • Faster performance
  • Backup for remote failure
  • May not agree (stale cache problem)
  • Local is likely to be incomplete
  • Note that these are quality attribute decisions!

9
This is a GoF Proxy
  • Pattern Proxy
  • Context/Problem Direct access to a real object
    is not desired or possible.
  • Solution Add a level of indirection with a
    surrogate proxy object that implements the same
    interface as the subject object, and has
    responsibility for controlling or enhancing
    access to it.

10
Error guidelines / patterns
  • Exceptions are especially appropriate when
    dealing with resource failures (disk, memory,
    network, database, etc.)
  • Pattern Convert Exceptions (Exception
    Abstraction)
  • Within a subsystem, avoid emitting lower level
    exceptions. Convert into ones meaningful at the
    subsystem level. It wraps the lower-level one
    and adds higher-level info.

11
Error guidelines / patterns, cntd
  • Pattern Name the problem, not the thrower
  • Assign a name to an exception that describes why
    the exception is being thrown, not the exception.
    This makes it easier for the programmer to
    understand what to do about it, and lets you
    group similar exceptions by rationale.
  • Pattern Centralized error 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.

12
Error guidelines / patterns, cntd
  • Pattern Error Dialog
  • Use a standard Singleton-accessed
    application-independent non-UI object to notify
    users of errors.
  • It wraps one or more UI dialog objects (suchas
    a GUI modal dialog, text console, sound beeper,
    or speech generator) and delegates the
    notification of the error to the UI objects.
  • Thus, output could go to both a GUI dialog and to
    a speech generator.
  • It will also report the exception to the
    centralized error logger.

13
Error Handling in UML
14
Abstract Factory
  • Weve already discussed factories which
    create objects for us, when the main user of
    those would be too complex by including this.
  • Abstract factory adds one more level of
    indirection you might do the object creations
    in different ways, depending upon some variables.
  • Java creates different GUI objects depending on
    what O/S it is operating under.
  • In NextGen POS, how to use the software for
    different hardware, for IBM versus NCR POS
    terminals.

15
Abstract Factory, cntd
  • Context / Problem How to create families of
    related classes that implement a common
    interface? E.g.,
  • cashDrawer JavaPOSDevicesFactory.getInstance().g
    etNewCashDrawer()
  • returns a cashDrawer for the right class (IBM vs
    NCR), depending on how you want it done.
  • Solution Define a factory interface (the
    abstract factory). Define a concrete factory
    class for each family of things to create.
    Optionally, define a true abstract class that
    implements the factory interface and provides
    common services to the concrete factories that
    extend it.

16
Abstract Factory, cntd
Write a Comment
User Comments (0)
About PowerShow.com