1 / 6

Abstract Factory Design Pattern

Abstract Factory Design Pattern. making abstract things. Abstract vs. Concrete. a number of design patterns use abstract and concrete classes abstract class – provides a list of abstract functions to be used by the pattern concrete class – provides implementation for the abstract functions

jnilles
Télécharger la présentation

Abstract Factory Design 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 FactoryDesign Pattern making abstract things

  2. Abstract vs. Concrete • a number of design patterns use abstract and concrete classes • abstract class – provides a list of abstract functions to be used by the pattern • concrete class – provides implementation for the abstract functions • abstract class pointers may point to concrete class objects and the abstract functions are overridden by concrete implementations • clients may not be concerned with implementations • various concrete objects may be assembled into a single container and operated uniformly • virtual functions would provide customized functionality per object

  3. Factory and Factory Methods • factory – an object for creating other objects called products • important when control over object creation is necessary: e.g. instead of just creating an object, factory may dynamically allocate it from an object pool, do complex configurations • contains methods for object creation • factory method (design pattern)- implements the actual object creation • usually returns a pointer to created object • specifies interface to be implemented (overridden) by subclasses, hence known as virtual constructor • why not regular constructor? cannot be overridden • example of behavior pattern • singleton class is an example of a factory, why?

  4. Abstract Factory • regular factory encodes product class names. May be inconvenient • in case need to make modification • in case need to re-use code for several related factories • abstract factorydesign pattern – separates interface and implementation • abstract factory – specifies creation interface • abstract product – specifies product interface to be manipulated by abstract factory • abstract factory method - product creation interface • concrete factory, product, method – implementation of respective interfaces • benefit of abstract factory pattern – client may not need to know (concrete) implementations to operate objects • abstract factory pattern is a creational pattern • abstract factory is often designed as a singleton pattern • a factory may be part abstract/part concrete

  5. Abstract Factory UML Diagram

  6. Review Questions • what is the difference between abstract and concrete classes? How can a client benefit from this difference? • what is: factory? product? factory method? • why are the factory and product separated into abstract and concrete?

More Related