0% found this document useful (0 votes)
40 views

Lecture 4 - Factory Method

The factory method pattern is a creational pattern that uses factory methods to create objects without specifying their exact classes. It defines an interface for creating objects but lets subclasses decide which class to instantiate. The pattern allows a class to defer instantiation to its subclasses, and makes a system independent of how its objects are created and represented.

Uploaded by

Abdul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Lecture 4 - Factory Method

The factory method pattern is a creational pattern that uses factory methods to create objects without specifying their exact classes. It defines an interface for creating objects but lets subclasses decide which class to instantiate. The pattern allows a class to defer instantiation to its subclasses, and makes a system independent of how its objects are created and represented.

Uploaded by

Abdul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 10

Software Design and Architecture

Factory Method Design Patterns


Factory Method
 The factory method pattern is a creational
pattern that uses factory methods to deal with
the problem of creating objects without having to
specify the exact class of the object that will be
created. This is done by creating objects by
calling a factory method.
 Intent
Define an interface for creating an object, but let
subclasses decide which class to instantiate.
Factory Method lets a class defer instantiation to
subclasses.
Factory Method
 Motivation
Consider the example of an ImageReader and
subclasses which implement the ImageReader
interface and instantiate objects of ImageReader for
reading images based on the type of image e.g.,
JpegReader, GifReader etc.
Factory Method
 Example
Factory Method
 Collaborations
The creator relies on its subclasses to define the
factory method so that it returns an instance of
the appropriate subclass.
Factory Method
Factory Method
 Related Patterns
 Abstract Factory pattern often implemented with
Factory Methods
 Template Methods contain calls to Factory
Methods
The End
Assignment
 What are the Advantages and
disadvantages of factory Method

You might also like