Top Banner
Deriving Abstract Factory Loosening the coupling when creating objects...
20

Deriving Abstract Factory Loosening the coupling when creating objects...

Jan 19, 2018

Download

Documents

Laureen Booker

BetaTown Change is the only constant in software dev. Receipts with bar code for easy scanning
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Deriving Abstract Factory Loosening the coupling when creating objects...

DerivingAbstract Factory

Loosening the coupling when creating objects...

Page 2: Deriving Abstract Factory Loosening the coupling when creating objects...

Prelude

  The Receipt class revisited– Add responsibility to print itself

– Provided by method

– Result:

Demo: code-demo/PayStationWithGUI

Page 3: Deriving Abstract Factory Loosening the coupling when creating objects...

BetaTown

  Change is the only constant in software dev.  Receipts with bar code for easy scanning

Page 4: Deriving Abstract Factory Loosening the coupling when creating objects...

Code View

  Something must be done at:

A ”new BarCodeReceiptImpl()” in BetaTown

Page 5: Deriving Abstract Factory Loosening the coupling when creating objects...

Yet another Variability

  New variability point! Resulting configurations:

Page 6: Deriving Abstract Factory Loosening the coupling when creating objects...

The Compositional Design

Page 7: Deriving Abstract Factory Loosening the coupling when creating objects...

3-1-2

  Cranking the 3-1-2 blindly– 3) Identify what varies: instantiation of receipts– 1) Interface express responsibility: ReceiptIssuer– 2) Compose behavior: delegate to ReceiptIssuer

Page 8: Deriving Abstract Factory Loosening the coupling when creating objects...

Trying it out

  Quickly add a test:

  Low cohesion: object creation in two different objects – why not make one cohesive object???

Page 9: Deriving Abstract Factory Loosening the coupling when creating objects...

More Cohesive Design

  One place to “create delegates”: the factory

Page 10: Deriving Abstract Factory Loosening the coupling when creating objects...

Usage

Only one delegate!

Page 11: Deriving Abstract Factory Loosening the coupling when creating objects...

  Why TestTownFactory()?

Page 12: Deriving Abstract Factory Loosening the coupling when creating objects...

To Configure BetaTown

  The factory for BetaTown

Important benefit: all configuration is contained in one java source file!

Page 13: Deriving Abstract Factory Loosening the coupling when creating objects...

TestTownFactory

Page 14: Deriving Abstract Factory Loosening the coupling when creating objects...

The Compositional Process

Page 15: Deriving Abstract Factory Loosening the coupling when creating objects...

The Process Again Again

Page 16: Deriving Abstract Factory Loosening the coupling when creating objects...

Or…

Page 17: Deriving Abstract Factory Loosening the coupling when creating objects...

Abstract Factory

Page 18: Deriving Abstract Factory Loosening the coupling when creating objects...

Deriving it…

  3-1-2 has derived yet another design pattern– An object (factory) whose

responsibility it is to create objects (products) that the client need.

Page 19: Deriving Abstract Factory Loosening the coupling when creating objects...

Deriving it…

Page 20: Deriving Abstract Factory Loosening the coupling when creating objects...

Mandatory Note

  Abstract Factory is complex– Lots of relations– Easy to get confused or miss the whole idea– Easy to misimplement a little with BIG consequences

  Morale– Do not underestimate it in the Mandatory…