1 / 5

Abstract Factory Pattern

Abstract Factory Pattern. From Gamma: Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Jonathan Ma. What is the Abstract Factory Pattern used for?.

izzy
Download Presentation

Abstract Factory Pattern

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Abstract Factory Pattern From Gamma: Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Jonathan Ma

  2. What is the Abstract Factory Pattern used for? • Suppose you have a program that produces GUI elements, such as buttons, title bars and you want it to vary depending on the appearance or the OS. • Using this pattern allows you to create families of objects each depending on a specific category (Windows, Linux, Mac) without knowing the concrete classes (WinButton, WinScrollbar)

  3. Pros and Cons for the Pattern Disadvantages Large number of classes needed: Will need to generate a+b+ab +1 total classes, where a is number of factories and b is number of abstract objects. Can be difficult extend functionality for individual objects Need to change the abstract interface and implement the interface in the concrete objects Can never access methods outside of the abstract object’s interface – this is because you only know the static type, not the dynamic type. Advantages • Promotes consistency across the program • Promotes easy switching of object categories. • Just substitute the concrete factory in use. • You never have to work with concrete objects, only concrete factories. • Extremely useful if using the program as a library.

  4. Maximizing Benefits of Pattern • Build a collaborator class or a make function that generates the object or factory needed based on an input string. • Advantage: You never even have to create a concrete factory object, or have the user know it even exists! • Make concrete factories singletons. • Only one factory is needed for the whole program – allows you to do bookkeeping operations from within the concrete factory.

More Related