Design Pattern Flashcards
Composite Design Pattern
Compose objects into tree structures that represent whole-part hierarchies
Composite lets clients treat individual objects and compositions of objects uniformly
This pattern is a partitioning design pattern
Allows a group of objects to be treated the same way as a single-instance of an object
Data Transfer Object Design Pattern
Rather then force a Facade class to maintain a large interface to support domain composed of a large number of data attributed.
The Facade encapsulates the key data of a domain object in a simple class (the Data Transfer Object) and returns the DTO object (not individual data elements) to clients
In this way, one call to the Façade is needed to get all the data that the Façade is willing to give for a domain object.
Without using this pattern, many calls might be needed to access the key data of a domain object needed to perform a particular function.
Decprator Design Pattern
provides a flexible alterative to sub-class for extending functionality
Inheritance is one form of extension, but not necessarily the best way to achieve flexibility in our designs.
In our designs we should allow behavior to be extended w/o the need to modify existing code (open-Closed Principle)
Composition and Delegation can often be used to add new behaviors at runtime.
Facade
The facade design pattern specifies the creation of a class with a unified interface to a set of interfaces (publicly exposed methods) in a subsystem.
The facade pattern defies a higher-level interface that makes a subsystem easier to use.
By using the Facade pattern, we provide a simple interface to a complex subsystem. This interface is good enough for most clients, more sophisticated clients can look beyond the facade.
We can also decouple the classes of a subsystem from client classes and other subsystem, thereby promoting subsystem independence and
Factory Design Pattern
defines a technique to encapsulate the details of object creation in a single class known as a “Factory” class whose job it is as to create concrete instances of various objects that implements a given interface.
The other objects in the application that need new objects created by the factory by the factory class are known as “clients” of the factory.
Flyweight Design Pattern
is used to reduce the memory and resources usage for complex applications containing many hundreds, thousands or millions of duplicate objects.
To do this, the flyweight pattern specifies a solution whein only one object holding a specific value (or specific set of values) is ever created - rather than 2, or 10, 10000 objects each holding the same value.
Memento Design Pattern
is a design pattern that permits the current state of an object to be “externally” stored w/o breaking the rules of Encapsulation or the SRP principle.
The domain object can be modified as required but can be restored to the saved state at any time.
To support an undo operation, an application must be able to revert to the state in which it existed before a user executed an operation.
There are at least a couple ways you can implement this: Operation Reversal, and State Storage
Monostate Design Pattern
defines a “conceptual singleton”.
It is not a true singleton because multiple instances of the Monostate class can be created, but all data attributes of a Monostate class are declared as “static” so that all instances of the Monostate class share the same (static) data attributes values.
In this way, you can create one or more thousand instances of a Monostate class and all of those objects will share and see the same values for the Monostate’s data attributes.
Users of a Monostate objects do not behave differently than users of a regular object. The users do not need to know that the object is monostate
Subclasses of a Monostate classes are Monostates. Indeed, all the derivatives of a Monostate are part of the same Monostate. They all share the same static variables
Since the methods of a Monostate are not static, they can be overridden in a derivative. Thus different derivatives can offer different behavior over the same set of static variables.
MVC
design pattern is a widely used architectural pattern in software engineering, particularly in developing user interfaces.
Null Object Design Pattern
If an object reference may be optionally “null” and this reference must be checked before every use and the result of a “null” check is to do nothing or assign a suitable default value -
Then we can create which implements the same interface as the other implementations objects, provide implementations for all the requisite methods that do nothing to provide default results and use an instance of this class whenever the object reference would have beeen “null”.
Observer Design Pattern
allows one object (or more) - the observer - to watch another - the subject.
The Observer pattern allows the subject and observer to form a publish-subscribe relationship.
Throug the Observer pattern, observer can register to receive events from the subject from the subject. When the subject needs to inform its observer of an event, it simply sends the event to each registered observer
inform its observer of an event, it simply sends the event to each registered observer
This pattern is a behavioral design pattern.
The observer pattern is also known as the broadcaster-listener or publisher-subscriber pattern.
Power Type Design Pattern
patterns specifies a technique for removing the unchanging “type” data from classes representing individual objects and instead creating a new second object that will contain that unchangind “type” data (i.e., the “Power Type”)
The individual objects of a given type (i.e., the individual aircraft in our example) will own a reference to a “power type” object that they can use to access the power type object data values. specifies a technique for removing the unchanging “type” data from classes representing individual objects and instead creating a new second object that will contain that unchanging “type” data (i.e., the “Power Type”)
The Power Type pattern helps to reduce the space needed by a set of objects by removing the need to store duplicate data values.
Singleton Design Pattern
pattern is designed to restrict instantiation of a class to one object.
This pattern is implemented by creating a class w. A method that creates a new instance of the object only if one does not already exist.
If one does exist, it returns a reference to the object that already exists.
If not, a new instance is created and a reference to that new object is returned.
To make sure that the object cannot be instantitiated any other way the constructor is made either private or protected.
Strategy Design Pattern
pattern is designed to restrict instantiation of a class to one object.
This pattern is implemented by creating a class w. A method that creates a new instance of the object only if one does not already exist.
If one does exist, it returns a reference to the object that already exists.
If not, a new instance is created and a reference to that new object is returned.
To make sure that the object cannot be instantitiated any other way the constructor is made either private or protected.