Patterns Flashcards
What are the main categories of Design Patterns?
There are 3 different types of patterns:
- Creational patterns, such as Factory, Builder, Factory Method - they are all about different ways of instantiating object with non-trivial creation algorithm or unusual circumstances.
- Structural patterns, e.g. Proxy, Decorator, Bridge, Composite. This patterns identify common structures formed from language units and help to organize code into larger units in a comprehensible way.
- Behavioral patterns, e.g. strategy, command, chain of responsibility, template method, visitor. They specify a different kinds of interactions between language units.
What is Singleton pattern?
Singleton pattern is a creational one. It facilitates a limitation of instances of particular type to at-most one. It can be used in cases where different execution threads should use the same state to work properly, but now it is more often used as an optimization technique to prevent repeated instantiation of a stateless class.
What is Design Patterns and why anyone should use them?
Design Patterns are industry-known and described best practice solution to common problems in software development. Patterns are a good communication tool for developers. Facing a correct pattern implementation may inform you about what problem had occurred here. Patterns are also a ready-to-go toolkit for solving trivial problems.
What is Factory pattern?
Factory is a class that is dedicated to creating an instance of another type. It mostly used when object creation logic is not simple and exact return type is not known at compile-time and depends on a result of some calculations.
What is Criteria pattern?
Criteria pattern is a way to make a set of conditions to filter out a collection of objects. This pattern allows to split collecting this conditions and applying them, it assumes presence of logical operators to make more complex filter chains and re-usability of particular filters.
What is Template pattern?
Template pattern is a abstract class that specifies the general behavior through the sequence of methods, but leaves an implementation of some of this methods to subclasses
What is State pattern?
State is a behavioral pattern that allows to change an object’s behavior by changing its state. Normally, that means presence of a context as an entry point which delegates whole or a part of execution to inner state implementation.
What is Inversion of Control?
Inversion of Control is an approach to design dependencies between classes through abstractions rather than concrete implementations of them. Concrete implementations are set in an outer level manually of with dependency injection mechanism.
What is Null Object pattern?
Null Object is a way to represent missing or unavailable data without utilizing default language null reference. Null Object is an instance of desired class or subclass of it, so, according to Liskov Substitution principle it should be usable in every situation where instance of original class could be applied.
What is Builder pattern?
Builder pattern is a way to create an object incrementally, providing different pieces of data separately from each other.
What is Strategy pattern?
Strategy is a pattern of picking required implementation of algorithm in runtime based on input data or stored data.
What is Iterator pattern?
Iterator pattern is a way to access elements of collection one by one by defining a custom method to proceed to the next element. Iterator can be applied either to real collections that have some kind of representation in memory or to virtual collections that can be only evaluated by iterating over them.
What is Proxy pattern?
Proxy pattern is a way to represent access to some remote service as simple as a call to a method of some interface
What is Dependency Injection?
Dependency Injection is a practice of separation between declaring abstract dependencies and providing concrete implementations that fit to this contract
What is Bridge pattern?
Bridge separates interface and it’s implementation to allow them evolve independently.