Factory Method

factory method n.w
1 / 8
Embed
Share

The Factory Method design pattern is utilized to create objects without specifying the exact class, leading to reduced code repetition and enhanced abstraction. This pattern allows classes to defer instantiation to subclasses, promoting flexibility and reducing verbosity in code. However, it can also introduce confusion due to its abstract nature. Learn about the purpose, terminology, advantages, disadvantages, and references related to the Factory Method pattern.

  • Factory Method
  • Design Pattern
  • Creational Pattern
  • Abstraction
  • Code Flexibility

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Factory Method

  2. Intent/Purpose Factory Method is used to deal with a problem of creating objects without specifying the EXACT class of object that we will be creating or explicitly calling the object s constructor. As a result, we get less code repetition and a higher degree of abstraction This can be useful when a class cant anticipate the type of object it must create.

  3. Definition/Description A factory method is a creational pattern Its purpose is to define an interface for creating objects which allows a class to defer instantiation to a subclass Factory method is another, more abstract and elegant way of creating object with the same base class without using their constructor Multi-SubClass Constructor

  4. Terminology Product Product - usually an abstract type of object that a factory method will create Concrete Product Concrete Product a concrete instance of Product Creator Creator - abstract type/interface which returns an object of type Product. Concrete Creator Concrete Creator overrides the factory method in Creator

  5. UML

  6. Advantages Reduce code verbosity Have clear distinguishable name for the Factory Method unlike constructors Not required to create a new object when called, this adds to flexibility

  7. Disadvantages Code can become more confusing

  8. REFERENCES Design Patterns by Gang of Four Wikipedia Stack Overflow

More Related Content