Gof Flashcards
Which pattern restricts the initialization of a class to ensure that only one instance of the class can be created?
Singleton
Which pattern takes out the responsibility of instantiating a object from the class to a new class with only this responsibility?
Factory
Which pattern create a Factory for factory classes?
Abstract Factory
Which creates an object step by step and a method to finally get the object instance?
Builder
Which pattern creates a new object instance from another similar instance and then modify according to our requirements?
Prototype
Which pattern creates an interface so that two distinct interfaces can work together?
Adapter
Which pattern creates an interface with multiple pieces or leaves in a part-whole?
Composite (FileSystemItem -> File, Directory that contains files)
Which pattern creates a new object that controls an object?
Proxy (Functionality -> AdminFunctionality)
Which pattern caches objects so that they do not need to be instantiated again for the same functionality?
Flyweight
Which pattern creates an interface so that it lowers complexity of its parts?
Facade (SoundSystem, TvSystem -> HomeTheaterFacade)
Which pattern creates an abstraction so that both implementations and interfaces can grow separately?
Bridge
abstract vehicle - bus,bike
interface WorkShop - produce, assemble)
Which pattern creates an abstract class that defines the skeleton and passes the responsibility of implementing some steps to the subclasses?
Template
(Abstract BuildHouse -> GlassHouse, WoodenHouse)
Which pattern abstract communications between objects, decoupling them into a single interface?
Mediator
Which pattern decouples client requests that follow a order so that each step is not coupled?
Chain of responsibility
(ATM dispenser with 50DollarDispense, 20DollarDispense, etc)
Which pattern makes objects be notified of changes made to their interested objects?
Observer
interface Observer -> class YtSubscriber
interface Subject -> class YtChannel
Which pattern enables multiple implementations to be selected at runtime?
Strategy
interface PaymentStrategy -> CreditCard, Cash
Which pattern decouples the sender of the request from the receiver?
Command
interface Command -> class TurnLightOnCommand
Which pattern decouples if-else implentations to be applyed when the object internal memory is changed?
State
interface TvState -> OnState, OffState
doAction now would do different things depending on the internal state
Which pattern decouples implementations from classes that are similar, without ever changing the original classes?
Visitor
interface FruitColorVisitor
visitBanana
visitApple
interface FruitPriceVisitor
visitBanana
visitApple
Which defines a grammatical representation for a language and provides an interpreter to deal with this grammar?
Interpreter
Calculator example
Which pattern allows us to recover previous states of an object so that it can be restored?
Memento
classic undo redo
Which pattern decouples how we trasverse through objects of multiple collections while having types of collections?
Iterator
Which pattern is used to modify the functionality of an object at runtime?
Decorator
interface Coffee
CoffeeLatteDecorator implements Coffee