1/6
The design patterns covered in COMP2511
What is the core use case for the “Composite” Design Pattern? What are its features?
Binary Tree shaped system, manipulating a single instance of an object in the same way we would manipulate a group of them.
Leaf and Composite nodes. Composite nodes can hold their own values and 1-2 other nodes. Leaf nodes only hold their own value and have parent nodes.
What is the core use case for the “Strategy” Design Pattern? What are its features?
When a class can have multiple types of a behaviour that differ in functionality. (Family of algorithms)
Vary behaviour without changing the context class.
Multiple behaviour classes implement a shared interface.
The class holds an object of type interface.
This interface can be changed depending on the class behaviour, allowing for different implementations of the interface.
What is the core use case for the “Factory” Design Pattern? What are its features?
Creating instances of objects/classes. Allows subclasses to alter the type of object that is created.
Creator and Product interface/abstract classes.
The subclasses of creator focus on creating a certain kind of product subclass.
What is the core use case for the “Abstract Factory” Design Pattern? What are its features?
Creating instances of objects that each have different variations.
Interface for the kind of factory. Implementations of interface are grouped around the different variations an object can have.
Each product that can be made by a factory is an interface, with each implementation being one of the object variations.
What is the core use case for the “Singleton” Design Pattern? What are its features?
Creating only one instance of an object. Preventing more than one instance from being instantiated.
Private constructor
Class holds itself (PRIVATE STATIC)
Instance method check if the attribute that holds the class is null or not. Makes new instance if it is null, returns exisiting instance if not.
Synchronized constructor and instantiation method.
What is the core use case for the “Decorator” Design Pattern? What are its features?
Creating objects that have a lot of “add-ons”
Decorator interface
Each implementation of decorator holds a decorator.
If an operation is called on a decorator, it calls the operation on the decorator it holds as well, until it recurses to an instance where the decorator is null.
What is the core use case for the “Observer” Design Pattern? What are its features?
Creating objects that emit/respond to events/changes.
Observer interface with an ‘update’ method to be called when an event occurs.
Subject interface with the ‘attach’ ‘detach’ and ‘notify’ method.
Subjects are subscribed to by objects, they are the emitters of events.