SE322 · Chapter 6 · Lecture 1 · Annotated SlidesDesign Patterns and the Abstract Factory
PDF
Overview

Design Patterns and the Abstract Factory

Design patterns are recurring solutions to object-oriented design problems in a given context, smaller in scale than architectural patterns. They are classified by purpose (creational, structural, behavioural) and by scope (class or object). Creational patterns control how objects are created. The first one, Abstract Factory, gives a client one interface for creating a whole family of related products (dark-theme widgets, advanced computer parts) without naming their concrete classes, so switching families means swapping one factory object.

Purpose and scope

Creational = creating objects; structural = composing structures; behavioural = interaction and responsibilities. Class scope = design time; object scope = run time.

Five creational patterns

Abstract Factory, Factory Method, Builder, Prototype, Singleton.

Abstract Factory roles

AbstractFactory (one create method per product), ConcreteFactory per family, AbstractProduct per product type, ConcreteProducts, and a Client that sees only the abstract types.

Trade-off

Adding a new family is easy (a new factory and products, OCP); adding a new kind of product touches every factory. Many classes.

How the lecture is organized

  • Slides 1–7Design patterns: definition, purpose and scope, documentation, creational patterns
  • Slides 8–17Abstract Factory: intent, the theme example, structure, adding families and products
  • Slides 18–31Computer-store example: products, factories, client and main program
  • Slides 32–39Step-by-step summary, pros and cons, the car-factory exercise, recap

Exam focus

Final 252 Q6 examined creational patterns through Builder and Singleton (Lectures 2–3). For Abstract Factory expect a design question: given a scenario with product families (themes, car brands, computer grades), name the pattern, draw the class diagram with factory and product interfaces, and explain how a new family is added.

How to read this page

Every original slide is shown unchanged. Yellow marks on a slide point to a numbered note: hover or tap a mark to jump to its note, and hover a note to see its marks. Questions tagged Past exam appeared on a real paper; Prediction questions are likely angles, not confirmed.

All 39 slides
  1. 1 Slide 1
  2. 2 Lecture Outlines
  3. 3 Patterns in Detailed Design
  4. 4 Classifications of Design Patterns
  5. 5 Classifications of Design Patterns
  6. 6 Patterns
  7. 7 Creational Design Patterns
  8. 8 The Abstract Factory Pattern
  9. 9 The Abstract Factory Pattern
  10. 10 Extra: Question – Dark and Light themes
  11. 11 Extra: The theme demo running
  12. 12 Extra: Theme example class diagram
  13. 13 Extra: Theme example code, steps 1–3
  14. 14 Extra: Theme example code, steps 4–5
  15. 15 The Abstract Factory Pattern: structure
  16. 16 The Abstract Factory Pattern: adding a new family
  17. 17 The Abstract Factory Pattern: adding a new product
  18. 18 The Abstract Factory Pattern - Example
  19. 19 The Abstract Factory Pattern – Example: the computer store
  20. 20 The Abstract Factory Pattern – Example: class diagram
  21. 21 The product interfaces
  22. 22 The CPU
  23. 23 monitor
  24. 24 The
  25. 25 The CPU Product Implementation
  26. 26 Other Product Implementation
  27. 27 The Abstract Factory Pattern - Example
  28. 28 Factory Interfaces and
  29. 29 The Client Computer Design
  30. 30 Slide 30
  31. 31 Extra: The computer-parts demo running
  32. 32 Slide 32
  33. 33 Cons & Pros of Abstract Factory
  34. 34 Abstract Factory Step by Step Summary (repeated)
  35. 35 Cons & Pros of Abstract Factory (repeated)
  36. 36 Extra Example: RiyadhHQ car factories
  37. 37 Extra: RiyadhHQ class diagram
  38. 38 Extra: Do we create concrete classes?
  39. 39 Summary
Slide 1 / 39

Slide 1

Slide 1: Slide 1

Notes

  1. Chapter 6 starts design patterns, the detailed-design counterpart of Chapter 4’s architectural patterns. This lecture: what design patterns are, how they are classified, and the first creational pattern, Abstract Factory.

Slide 2 / 39

Lecture Outlines

Slide 2: Lecture Outlines

Notes

  1. First, how design patterns differ from architectural patterns.

  2. Then how they are classified (purpose and scope) and documented.

  3. Then the creational patterns, starting with Abstract Factory and its computer-store example.

Slide 3 / 39

Patterns in Detailed Design

Slide 3: Patterns in Detailed Design

Notes

  1. Design patterns are recurring solutions to object-oriented design problems in a particular context. They give templates that solve problems efficiently and consistently, so developers don’t reinvent the wheel.

  2. They are different from architectural patterns (Chapter 4, slide 11 of Lecture 1): architectural patterns fix the system-wide structure; design patterns work at the level of classes and objects inside a subsystem and don’t change the overall structure.

Slide 4 / 39

Classifications of Design Patterns

Slide 4: Classifications of Design Patterns

Notes

  1. Patterns are classified by purpose (what kind of problem they solve) and scope (next slide).

  2. Creational: deal with the creation of objects (this chapter).

  3. Structural: deal with composing objects and classes into larger structures (Chapter 7: Adapter, Composite…).

  4. Behavioural: deal with how classes interact, how behaviour varies, and how responsibilities are assigned between objects (Chapter 7: Observer…).

Exam angle

PredictionQ1

Patterns that deal with how classes interact and how responsibilities are assigned between objects are:

  1. Behavioral
  2. Creational
  3. Structural
  4. Architectural
Show answer

A. Behavioral

Slide 5 / 39

Classifications of Design Patterns

Slide 5: Classifications of Design Patterns

Notes

  1. The scope criterion says whether a pattern applies mainly to classes or to objects.

  2. Class-level patterns deal with relationships between classes, fixed at design time through inheritance. Examples in the table: Factory Method (creational), Adapter (structural), Interpreter and Template Method (behavioural).

  3. Object-level patterns deal with relationships between objects, set up at run time through composition. Most patterns are here: Abstract Factory, Builder, Prototype, Singleton (creational); Adapter, Bridge, Composite, Decorator, Façade, Proxy (structural); Chain of Responsibility, Command, Iterator, Mediator, Memento, Flyweight, Observer, State, Strategy, Visitor (behavioural).

Exam angle

PredictionQ1

Classify Abstract Factory, Composite and Observer by purpose and scope.

Show answer

Abstract Factory: creational, object scope. Composite: structural, object scope. Observer: behavioural, object scope.

Slide 6 / 39

Patterns

Slide 6: Patterns

Notes

  1. Each pattern is documented with the same categories, so patterns can be compared and looked up.

  2. The categories: name and classification, intent (what problem it solves), also known as, motivation (an example scenario), applicability (when to use it), structure (UML class diagram), participants, collaborations, consequences (good and bad effects), implementation, sample code, known uses, related patterns.

  3. Note on the slide: this course is not concerned with presenting the full documentation for each pattern; focus on intent, structure and participants.

Slide 7 / 39

Creational Design Patterns

Slide 7: Creational Design Patterns

Notes

  1. Creational patterns abstract and control how objects are created, by giving clients a common creational interface instead of scattered new ConcreteClass() calls.

  2. The five: Abstract Factory, Factory Method, Builder, Prototype, Singleton. This chapter covers Abstract Factory, Factory Method, Builder and Singleton.

Exam angle

PredictionQ1

Which of these is NOT a creational pattern?

  1. Composite
  2. Builder
  3. Singleton
  4. Prototype
Show answer

A. Composite

Slide 8 / 39

The Abstract Factory Pattern

Slide 8: The Abstract Factory Pattern

Notes

  1. The Abstract Factory is an object-creational pattern that manages and encapsulates the creation of a set of objects that belong together: a family of products.

  2. Its intent: provide an interface for creating families of related objects without specifying their concrete classes.

  3. Like all creational patterns it has creator classes (the factories) and product classes. (Some creational patterns, such as Singleton, fuse creator and product into one class.)

Exam angle

PredictionQ1

What is the intent of the Abstract Factory pattern?

  1. Provide an interface for creating families of related objects without specifying their concrete classes
  2. Ensure a class has exactly one instance
  3. Construct a complex object step by step
  4. Create objects by copying a prototype
Show answer

A. Provide an interface for creating families of related objects without specifying their concrete classes

Slide 9 / 39

The Abstract Factory Pattern

Slide 9: The Abstract Factory Pattern

Notes

  1. The same definition, plus the two benefits. Encapsulation: the client knows the abstract product names (Button, Textbox) but not the concrete classes (DarkButton, LightTextbox).

  2. Flexibility: a new family is added by creating a new factory, without changing the client.

Slide 10 / 39

Extra: Question – Dark and Light themes

Slide 10: Extra: Question – Dark and Light themes

Notes

  1. The exercise: a program with a Dark theme (black button and text field) and a Light theme (white ones). Instead of if (dark) checks everywhere, use Abstract Factory.

  2. The factory interface GUIFactory declares createButton() and createTextField().

  3. DarkThemeFactory returns a DarkButton and DarkTextField; LightThemeFactory returns the light versions. The client asks its factory for a Button and a TextField and never knows which concrete class came back.

  4. Adding a Blue theme means adding BlueThemeFactory, BlueButton and BlueTextbox, with no change to the client. In one line: Abstract Factory is a “one-stop shop” for creating a related family of objects while hiding their concrete classes.

Slide 11 / 39

Extra: The theme demo running

Slide 11: Extra: The theme demo running

Notes

  1. The theme example running. Choosing Dark and pressing Apply Theme swaps in the DarkThemeFactory, and the window shows a dark button and text box; choosing Light swaps in the LightThemeFactory. The client code that builds the window is identical in both cases; only the factory object changed.

Slide 12 / 39

Extra: Theme example class diagram

Slide 12: Extra: Theme example class diagram

Notes

  1. The class diagram mapped onto the pattern’s role names. «interface» GUIFactory (AbstractFactory) declares createButton() and createTextField().

  2. «interface» Button (AbstractProductA) and TextField (AbstractProductB) are the product types the client uses.

  3. LightThemeFactory (ConcreteFactory1) creates LightButton and LightTextField (ConcreteProductA1/B1); DarkThemeFactory (ConcreteFactory2) creates DarkButton and DarkTextField (A2/B2). The hollow triangles are realizations; the arrows from factories to products show what each creates.

  4. The Client (AbstractFactoryDemo) depends only on the three interfaces.

Slide 13 / 39

Extra: Theme example code, steps 1–3

Slide 13: Extra: Theme example code, steps 1–3

Notes

  1. The code, steps 1–3:

    CodeWhat it does
    interface GUIFactory { Button createButton(); TextField createTextField(); }Step 1: the abstract factory, one create method per product type.
    class DarkThemeFactory implements GUIFactory {Step 2: a concrete factory for the dark family…
    public Button createButton() { return new DarkButton(); }…returns the dark button, typed as the abstract Button.
    public TextField createTextField() { return new DarkTextField(); } }…and the matching dark text field.
    class LightThemeFactory implements GUIFactory { … new LightButton() … new LightTextField() … }The light family, same shape.
    interface Button { void draw(); }Step 3: the abstract products.
    interface TextField { void display(); }
  2. The only place new DarkButton() appears is inside DarkThemeFactory. That is the point of the pattern.

Slide 14 / 39

Extra: Theme example code, steps 4–5

Slide 14: Extra: Theme example code, steps 4–5

Notes

  1. Steps 4–5:

    CodeWhat it does
    class DarkButton implements Button { public void draw() { …"Drawing Dark Button"… } }Step 4: concrete products, one per family per product type.
    class LightTextField implements TextField { public void display() { …"Showing Light TextField"… } }(LightButton and DarkTextField are written the same way.)
    GUIFactory lightFactory = new LightThemeFactory();Step 5, the client: pick a family once…
    Button lightBtn = lightFactory.createButton(); TextField lightTxt = lightFactory.createTextField();…ask that factory for the parts, typed as abstract products…
    lightBtn.draw(); lightTxt.display();…and use them. Prints “Drawing Light Button”, “Showing Light TextField”.
    GUIFactory darkFactory = new DarkThemeFactory(); … darkBtn.draw(); darkTxt.display();The dark run is the same code with a different factory.
Slide 15 / 39

The Abstract Factory Pattern: structure

Slide 15: The Abstract Factory Pattern: structure

Notes

  1. The general structure. Clients only know the creator and product interfaces, so behaviour can vary without changing client code.

  2. Every factory must obey the Factory interface (AbstractFactory with createProductA(), createProductB()), and every product its Product interface.

  3. Creator classes on the left (ConcreteFactory1, ConcreteFactory2); product classes on the right (ConcreteProductA1, B1, A2, B2). Each concrete factory creates exactly one family: factory 1 → A1 and B1; factory 2 → A2 and B2.

Exam angle

PredictionQ1

Name the participants of the Abstract Factory pattern.

Show answer

AbstractFactory (interface with one create method per product), ConcreteFactory (one per family), AbstractProduct (one interface per product type), ConcreteProduct (one class per family per product), and Client (uses only AbstractFactory and AbstractProduct).

Slide 16 / 39

The Abstract Factory Pattern: adding a new family

Slide 16: The Abstract Factory Pattern: adding a new family

Notes

  1. Adding a new family (the red parts): add ConcreteFactory3, which implements the existing AbstractFactory, plus ConcreteProductA3 and B3, which implement the existing product interfaces.

  2. No existing class changes: the system is extended, not modified. This is the Open-Closed Principle in action, and the case Abstract Factory handles best.

Slide 17 / 39

The Abstract Factory Pattern: adding a new product

Slide 17: The Abstract Factory Pattern: adding a new product

Notes

  1. Adding a new product to the existing families is harder: add «interface» AbstractProductC and a concrete C product for every family (C1, C2, C3)…

  2. …and add createProductC() to the AbstractFactory interface and therefore to every concrete factory. Existing classes must change, which is the pattern’s main weakness.

Exam angle

PredictionQ1

Why is adding a new product type harder than adding a new family in Abstract Factory?

Show answer

A new family only needs a new concrete factory and new concrete products, with no change to existing code. A new product type needs a new create method in the AbstractFactory interface, so every existing concrete factory must be modified (plus a new abstract product and one concrete product per family).

Slide 18 / 39

The Abstract Factory Pattern - Example

Slide 18: The Abstract Factory Pattern - Example

Notes

  1. The textbook example: a computer store that sells two grades of computer, advanced (top of the line) and standard (inexpensive). More grades will come.

  2. Each computer is made of products from its own grade: an advanced CPU, keyboard and monitor, or standard ones. The example uses only CPU, keyboard and monitor.

  3. For each product the system looks up information (reviews, customer comments, manufacturer notes) from remote sources, and each grade’s products come from different sources. So “advanced” and “standard” are product families.

Slide 19 / 39

The Abstract Factory Pattern – Example: the computer store

Slide 19: The Abstract Factory Pattern – Example: the computer store

Notes

  1. The store as a picture: a customer chooses an advanced or standard computer from the console menu (1 Advanced, 2 Standard).

  2. The computer store system builds that computer from its products.

  3. Each product is associated with one or more information sources, which are used to find out information about the product.

Slide 20 / 39

The Abstract Factory Pattern – Example: class diagram

Slide 20: The Abstract Factory Pattern – Example: class diagram

Notes

  1. The example’s class diagram. «interface» ComputerPartsFactory declares createMonitor(), createCPU() and createKeyboard().

  2. AdvancedComputerPartsFactory creates AdvancedCPU, AdvancedMonitor and AdvancedKeyboard; StandardComputerPartsFactory creates the standard ones.

  3. «interface» CPU, Monitor and Keyboard are the abstract products; Computer is the client and uses only the interfaces. Creator classes on the left, product classes on the right, exactly the general structure of slide 15.

Slide 21 / 39

The product interfaces

Slide 21: The product interfaces

Notes

  1. Step 1 of the example: the product interfaces.

    CodeWhat it does
    public interface Cpu { void displayCpuInformation(); }Every CPU, of any grade, can display its information.
    public interface Monitor { void displayMonitorInformation(); }The monitor contract.
    public interface Keyboard { void displayKeyboardInformation(); }The keyboard contract.
  2. In the UML on the left the method names are in italics: in UML, italics mark abstract operations (no body).

Slide 22 / 39

The CPU

Slide 22: The CPU

Notes

  1. The CPU product design: «interface» Cpu with the abstract displayCpuInformation(), realised by AdvancedCpu and StandardCpu.

  2. The code:

    CodeWhat it does
    public class AdvancedCpu implements Cpu {The advanced family’s CPU.
    public AdvancedCpu() { /* Constructor */ }
    @Override public void displayCpuInformation() { /* Implementation code */ } }Its own way of displaying information.
    public class StandardCpu implements Cpu { … @Override public void displayCpuInformation() { … } }The standard family’s CPU, same contract.
Slide 23 / 39

monitor

Slide 23: monitor

Notes

  1. The monitor product design follows the same shape: «interface» Monitor with displayMonitorInformation(), realised by AdvancedMonitor and StandardMonitor, each with a constructor and an @Override of the display method.

Slide 24 / 39

The

Slide 24: The

Notes

  1. The keyboard product design: «interface» Keyboard, realised by AdvancedKeyboard and StandardKeyboard.

  2. As the callout says, the pattern for designing products should now be visible: one interface per product type, one concrete class per family.

Slide 25 / 39

The CPU Product Implementation

Slide 25: The CPU Product Implementation

Notes

  1. The CPU implementations:

    CodeWhat it does
    public class AdvancedCpu { public AdvancedCpu() { } …Constructor intentionally left blank.
    public void displayCpuInformation() { … System.out.println("\nInformation retrieved from source A.\nDisplaying the advanced CPU’s information.\n"); }The advanced CPU gets its data from information source A (database A, file A…).
    public class StandardCpu { … displayCpuInformation() { … "retrieved from source B" … } }The standard CPU gets its data from source B.
  2. Each concrete product knows how to reach its own source (connection, format, location). The client never sees this: it just calls displayCpuInformation().

Slide 26 / 39

Other Product Implementation

Slide 26: Other Product Implementation

Notes

  1. The keyboards and monitors are implemented the same way: advanced products print “Information retrieved from source A”, standard products “source B”, each followed by its own display text.

Slide 27 / 39

The Abstract Factory Pattern - Example

Slide 27: The Abstract Factory Pattern - Example

Notes

  1. The example class diagram again (same as slide 20) before the factories are built: the creator classes are next.

Slide 28 / 39

Factory Interfaces and

Slide 28: Factory Interfaces and

Notes

  1. The factories in detail: «interface» ComputerPartsFactory with createMonitor(), createCpu(), createKeyboard().

  2. AdvancedComputerPartsFactory is connected to AdvancedMonitor, AdvancedCpu and AdvancedKeyboard; StandardComputerPartsFactory to the standard three. This design connects the products from the previous slides to the factories that abstract their creation.

Slide 29 / 39

The Client Computer Design

Slide 29: The Client Computer Design

Notes

  1. The client:

    CodeWhat it does
    class ComputerStore { private Monitor monitor; private Cpu cpu; private Keyboard keyboard;Its fields are abstract product types only.
    public ComputerStore(ComputerPartsFactory computerPartsFactory) {The factory is passed in: the store never chooses the family itself.
    this.monitor = computerPartsFactory.createMonitor();Ask the factory for each part…
    this.cpu = computerPartsFactory.createCpu(); this.keyboard = computerPartsFactory.createKeyboard(); }…all from the same family, so they always match.
    public void displayMonitorInfo() { monitor.displayMonitorInformation(); }Using a part: a call on the interface.
    … displayCpuInfo(), displayKeyboardInfo() …
  2. In the UML the client (Computer) depends on ComputerPartsFactory and on the Cpu, Monitor and Keyboard interfaces, and on nothing concrete.

Slide 30 / 39

Slide 30

Slide 30: Slide 30

Notes

  1. The main program:

    CodeWhat it does
    AdvancedComputerPartsFactory advancedFactory = new AdvancedComputerPartsFactory();Create one factory per family (the only place concrete factories are named).
    StandardComputerPartsFactory standardFactory = new StandardComputerPartsFactory();
    while (option != 0) { … option = scanner.nextInt();Menu: 0 Exit, 1 Advanced, 2 Standard.
    if (option == 1) cs = new ComputerStore(advancedFactory);Choosing the family = choosing the factory.
    else if (option == 2) cs = new ComputerStore(standardFactory);
    if (cs != null) { cs.displayMonitorInfo(); cs.displayKeyboardInfo(); cs.displayCpuInfo(); } }The same calls for either family.
  2. The console on the right shows option 1: every line says “retrieved from source A”, so all parts came from the advanced family.

Slide 31 / 39

Extra: The computer-parts demo running

Slide 31: Extra: The computer-parts demo running

Notes

  1. A Swing version of the example: picking Advanced or Standard in the Factory menu and pressing Apply swaps the factory, and the CPU, monitor and keyboard shown (AdvancedCPU RTX-Pro, AdvancedMonitor 4K HDR, AdvancedKeyboard Mechanical RGB) all switch family together.

Slide 32 / 39

Slide 32

Slide 32: Slide 32

Notes

  1. Steps 1–3: design the product interfaces (Cpu, Monitor, Keyboard); identify the families (standard, advanced); for each family, design concrete products that realise the interfaces.

  2. Steps 4–6: create the factory interface with one method per product interface (ComputerPartsFactory); create one concrete factory per family; associate each concrete factory with its family’s products.

  3. Step 7: create the client (Computer), associated with both the product interfaces and the factory interface.

  4. This recipe is the model answer to “apply Abstract Factory to …” questions: name the product interfaces, the families, the factory interface and the concrete factories, then draw them.

Exam angle

PredictionQ1

Apply the Abstract Factory pattern to a furniture shop that sells Modern and Victorian sets, each with a Chair and a Sofa. Name all classes and interfaces.

Show answer

Product interfaces: Chair, Sofa. Families: Modern, Victorian. Concrete products: ModernChair, ModernSofa, VictorianChair, VictorianSofa. Factory interface: FurnitureFactory with createChair(), createSofa(). Concrete factories: ModernFurnitureFactory, VictorianFurnitureFactory, each creating its own family. Client: Shop, which holds a FurnitureFactory and uses only Chair and Sofa.

Slide 33 / 39

Cons & Pros of Abstract Factory

Slide 33: Cons & Pros of Abstract Factory

Notes

  1. Con: a large number of classes (an interface per product, a class per product per family, a factory per family).

  2. Pros: concrete product classes are isolated, so they are easier to reuse; products within a family are guaranteed consistent; adding a new family needs no change to existing code, because additions are made by extension (OCP); modifiability increases. (The hidden con from slide 17: adding a new product type changes every factory.)

Exam angle

PredictionQ1

Give one disadvantage and two advantages of the Abstract Factory pattern.

Show answer

Disadvantage: many classes (and adding a new product type requires changing every factory). Advantages: concrete classes are isolated from the client; products of a family are always consistent; new families are added by extension without modifying existing code (OCP), increasing modifiability.

Slide 34 / 39

Abstract Factory Step by Step Summary (repeated)

Slide 34: Abstract Factory Step by Step Summary (repeated)

Notes

  1. The seven-step summary repeated (see slide 32).

Slide 35 / 39

Cons & Pros of Abstract Factory (repeated)

Slide 35: Cons & Pros of Abstract Factory (repeated)

Notes

  1. The pros and cons repeated (see slide 33).

Slide 36 / 39

Extra Example: RiyadhHQ car factories

Slide 36: Extra Example: RiyadhHQ car factories

Notes

  1. An exercise: RiyadhHQ is the client that requests cars from different branches, without creating JeddahMercedes or DammamBMW itself.

  2. CarFactory is the abstract factory: it defines the products RiyadhHQ can request, a Mercedes and a BMW.

  3. JeddahCarFactory makes JeddahMercedes and JeddahBMW; DammamCarFactory makes DammamMercedes and DammamBMW. Each city is a family.

  4. The questions: RiyadhHQ doesn’t need to know the city because it only uses CarFactory, Mercedes and BMW; switching factories at run time is just passing a different CarFactory object; and the example shows Abstract Factory because each concrete factory creates a consistent family of related products behind one interface.

Exam angle

PredictionQ1

Why does RiyadhHQ not need to know which branch produced its cars, and how does it switch branches?

Show answer

It depends only on the CarFactory interface and the abstract Mercedes and BMW types, so the concrete classes stay hidden in the branch factories. Switching branches means giving RiyadhHQ a different CarFactory object (JeddahCarFactory or DammamCarFactory) at run time; its own code does not change.

Slide 37 / 39

Extra: RiyadhHQ class diagram

Slide 37: Extra: RiyadhHQ class diagram

Notes

  1. The model diagram: «interface» CarFactory with makeMercedes() and makeBMW(); JeddahCarFactory and DammamCarFactory implement it.

  2. Client Riyadh HQ uses CarFactory and the abstract products Mercedes and BMW; JeddahMercedes/DammamMercedes and JeddahBMW/DammamBMW are the concrete products, each created by its own city’s factory.

Slide 38 / 39

Extra: Do we create concrete classes?

Slide 38: Extra: Do we create concrete classes?

Notes

  1. Yes, concrete classes are still written (DarkButton, LightTextField…), and concrete factories that instantiate them. Otherwise nothing real would exist.

  2. But the client doesn’t care: the point of the pattern is decoupling. Client code works only with abstract types (Button btn; GUIFactory factory = FactoryProvider.getFactory("dark"); btn = factory.createButton();) and never writes new DarkButton().

  3. Why it matters: a new NeonThemeFactory with NeonButton and NeonTextField needs no client change. Without the pattern you get if-else “spaghetti” creating new DarkButton() or new LightButton() all over the client.

Slide 39 / 39

Summary

Slide 39: Summary

Notes

  1. This lecture: design-pattern basics and the Abstract Factory.

  2. Next: the other creational patterns, Factory Method, Builder and Singleton.