Category «Design Patterns»

The Abstract Factory (The Factory Pattern – part 3)

1. Definition It provides an interface for creating families of related or dependent objects without specifying their concrete classes. 2. Case study 2.1 The problem You’re creating a car manufacturer simulator, where you can simulate the process of manufacturing cars. As you may know, petrol cars and diesel cars need different parts in their fuel systems, …

The Factory Method Patterm (The Factory Pattern – part 2)

1. Definition Defines an interface for creating an object, but lets subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. 2.Case study I’m from Japan, where you’ll see different types of Miso (an ingredient of traditional soup) at the supermarket in different regions. For example, in Eastern areas, dark red Miso …

The Strategy Pattern

1. Definition The strategy pattern defines a family of algorithms, encapsulate each one, and make them interchangeable 2. Case study 2.1 The Problem A couple of years ago, you started a restaurant. Your restaurant had become so successful that you started to hire employees. Your employee’s payments were determined by … Wage rate × working hours  Their …

The Decorator Pattern

1. Definition The decorator pattern allows you to attach additional responsibilities to an existing object dynamically. 2. Case study 2.1 The Problem You’re the owner of a pizza store. Because nowadays everyone uses the internet to order pizzas, you decided to have a web application for taking orders from customers. In your app, each pizza was …