Design Patterns Flashcards
What is the basis of almost all design patterns?
All patterns find some way to let some part of the system vary without affecting other parts.
What is the intent of the Strategy Pattern?
The intent of the Strategy Pattern is to define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithms vary independently from the clients that use it.
Strategy also captures the abstraction in an interface, and buries the implementation details in the derived class.
What is the intent of the Observer Pattern?
The intent of the Observer Pattern is to define a one-to-many dependency between objects so when one objects changes states, all of its dependents are notified and updated automatically.
What is the concept of loose coupling and what design pattern makes use of it?
Objects are loosely coupled when they can interact with each other but they have very little knowledge of each other.
The Observer Pattern makes use of this concept.
What are the classes involved in Java’s built-in Observer Pattern and what do they allow you to do?
The Observable class (which is the Subject) and the Observer class. They allow for a push or pull style of information from the subject.
What is the intent of the Decorator Pattern?
The intent of the Decorator Pattern is to attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
Which Java package is largely based on the Decorator Pattern?
The java.io package is mostly based on the Decorator Pattern.
What is the intent of the Factory Pattern?
The intent of the Factory Pattern is to define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
What is the intent of the Singleton Pattern?
The intent of the Singleton Pattern is to ensure that a class has only instance and provides a global point of access to it.
What is the intent of the Command Pattern?
The intent of the Command Pattern is to encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
What is the intent of the Adapter Pattern?
The intent of the Adapter Pattern is convert 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 is the intent of the Facade Pattern?
The intent of the Facade Pattern is to provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
What is the intent of the Template Method Pattern?
The intent of the Template Method Pattern is to define the skeleton of an algorithm in a method, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.