Design Patterns Flashcards
Is “separate the parts of the code that changes from what stays the same” a design principle?
Yes
Is “Program to an interface, not an implementation” a design principle?
Yes. Could be also program to a super type which can be replaced by something else
Is “Favor composition over inheritance” a design principle? Why?
Composition makes it easier to swap behavior. Inheritance is good to avoid code dup but maintenance is shitty
Is Strategy Pattern a design pattern? What does it say?
Yes. It defines a family of Algorithms, encapsulates them and makes them interchangeable.
What else does design patterns offer other than better maintenability?
Gives a shared vocabulary among developers. Patterns allow you to say more with less.
What does the observer pattern do?
The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically.
What does the Decorator pattern do?
Wraps alike classes one on top of the other to compound results. Example sum the cost of add-ons of the milkshake
What does the The Factory Method Pattern do?
defines an interface for creating an object, but lets subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
Example: build new customer() passed as argument to a class.
What does The Dependency Inversion Principle say? Is it OO?
Depend upon abstractions. Do not depend upon concrete classes. Yes
What does the command Pattern say?
The Command Pattern encapsulates a request as an object, thereby letting you parameterize other objects with different requests, queue or log requests, and support undoable operations.
What does the adapter pattern say?
The Adapter Pattern converts the interface of a class into another interface the clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.
What does the facade pattern do?
The Facade Pattern provides a unifi ed interface to a set of interfaces in a subsytem. Facade defi nes a higherlevel interface that makes the subsystem easier to use.
What’s the Template Method Pattern?
The Template Method Pattern defi nes the skeleton of an algorithm in a method, deferring some steps to subclasses. Template Method lets subclasses redefi ne certain steps of an algorithm without changing the algorithm’s structure.
Example: OnCalculate ()
What is the Hollywood principle and what design pattern implements it?
The Hollywood Principle Don’t call us, we’ll call you. The template Method Pattern
What does the iterator pattern do?
The Iterator Pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.