Design Patterns: Factory PDF
Document Details
Uploaded by EndorsedThermodynamics
Hogeschool PXL
Tags
Summary
This document discusses design patterns, focusing on the Factory pattern. It explains the Factory method, abstract factory concept, and other related ideas in software development. The document also includes the UML diagrams and examples to illustrate these design patterns. The context is likely a course or lecture material on software engineering.
Full Transcript
Design Patterns: Factory 43AON3150 Software Engineering Hogeschool PXL – Elfde-Liniestraat 24 – B-3500 Hasselt www.pxl.be - www.pxl.be/facebook What is wrong with “new”? new → things get concrete This code is not ”closed for modification” PART 1 Pizzashop Design P...
Design Patterns: Factory 43AON3150 Software Engineering Hogeschool PXL – Elfde-Liniestraat 24 – B-3500 Hasselt www.pxl.be - www.pxl.be/facebook What is wrong with “new”? new → things get concrete This code is not ”closed for modification” PART 1 Pizzashop Design Principle 1 New pizza’s are added … Encapsulating object creation SimplePizzaFactory Refactor the PizzaStore Discussion 1. What have we accomplished? 2. Could we have used a static createPizza method? Pro/con? UML Simple Factory isn’t a GoF Pattern. This is not “Factory”, but quite useful and worth mentioning! PART 2 Franchising the pizza store Stores in different cities serve local styles of pizza How do we deal with that? Using the simple factory approach We want more “quality control” Each local store does things differently → we want uniformity (quality) Solution: → an abstract PizzaStore An abstract PizzaStore Allowing the subclasses to decide Pizzas are the products that get created Some real pizzas The FACTORY METHOD pattern The Factory Method Pattern encapsulates object creation by letting subclasses decide what object to create. Factory Method lets a class defer instantiation to subclasses. UML Bron: https://www.dofactory.com/net/factory-method-design-pattern Design Principle Depend upon abstractions. Do not depend upon concrete classes. This is also known as the “Dependency Inversion Principle”: Our high-level components should not depend on our low-level components; rather they should both depend on abstractions. DIP applied to the pizza store case PART 3 Ensuring consistency in ingredients… Families of ingredients… … demands for ingredient factories! Reworking the pizza Rework the pizza (2) Rework the pizza store What have we done? Abstract Factory → provide a means of creating a family of products (using an interface) We decouple our code from the actual factory that creates the products → multiple factories are possible The ABSTRACT FACTORY pattern The Abstract Factory Pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. UML