Skip to Content
Design Patterns Explained: A New Perspective on Object-Oriented Design
book

Design Patterns Explained: A New Perspective on Object-Oriented Design

by Alan Shalloway, James R. Trott
July 2001
Beginner to intermediate
368 pages
6h 52m
English
Addison-Wesley Professional
Content preview from Design Patterns Explained: A New Perspective on Object-Oriented Design

Learning the Abstract Factory Pattern: Implementing It

Example 10-3 shows how to implement the Abstract Factory objects for this design.

Example 10-3. Java Code Fragments: Implementation of ResFactory
abstract class ResFactory {
  abstract public DisplayDriver getDispDrvr();
  abstract public PrintDriver getPrtDrvr();
}

class LowResFact extends ResFactory {
  public DisplayDriver getDispDrvr() {
    return new LRDD();
  }
  public PrintDriver getPrtDrvr() {
    return new LRPD();
  }
}

class HighResFact extends ResFactory {
  public DisplayDriver getDispDrvr() {
    return new HRDD();
  }
  public PrintDriver getPrtDrvr() {
    return new HRPD();
  }
}

To finish the solution, I have the ApControl talk with the appropriate factory object (either LowResFact or HighResFact); this ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Design Patterns Explained: A New Perspective on Object-Oriented Design, Second Edition

Design Patterns Explained: A New Perspective on Object-Oriented Design, Second Edition

Alan Shalloway, James R. Trott
Design It!

Design It!

Michael Keeling

Publisher Resources

ISBN: 0201715945Purchase book