Please enable JavaScript.
Coggle requires JavaScript to display documents.
Design Pattern (Behavior Pattern (Iterator (when to use, Definition,…
Design Pattern
Behavior Pattern
Definition
concerned with algorthms and the assignment of responsibilities between objects. They shift your focus away from flow of control to let you concentrate jest on the way objects are interconnected
-
Mediator
-
usage
decouple objects from each other we need a mediator, which will contact the object on behalf of the other object,hence providing loose coupling between them. The object only needs to know about the mediator, and perform operations on it. The mediator will perform operations on the required underlying object in order to get the work done.
when to use
-
A set of objects communicate in well-defined but complex ways. The resulting inter dependencies are unstructured and difficult to understand
A behavior that is distributed between several classes should be customizable without a lot of sub-classign
-
-
Command
Definition
encapsulate a request as an object, thereby letting the developer to parameterize clients with different requests, queue or log request, and support undoable operation
-
-
Observer
when to use
When an abstractions has two aspects, one dependent on the other
When a change to one object requires changes others and you don't know many objects need to be changed
Definition
Defines a one-to-many between objects so that when one object changes state, all its dependents are notified and updated automatically.
-
ChainOfResponsibility
when to use
More than one objects may handle a request, and the handler isn't know a priori. The handler should be ascertained automatically.
-
-
Definition
a behavior pattern in which a group of objects is chained together in a sequence and a responsibility is provided in order to be handled by the group.If an object in the group can process the particular request, it does so and returns the corresponding response. Otherwise, it forwards the request to the subsequent object in the group
usage
The intent of this pattern is to avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. We chain the receiving objects and pass the request along the chain until an object handles it.
State
-
usage
designing an efficient structure for a class , a typical instance of which can exist in many different states and exhibit different behavio depending on the state it is in
The State pattern suggests moving the state-specific behavior out of the Context class into a set of separate cleasses referred to as State class
when to use
Operations have large, multipart conditional statements that depend on the object's state.This state is usually represented by one or more enumerated constant.
an object's behavior depends on its state, and it must change its behavior at run-time depending on that state
Strategy
Definition
Define a family of algorithms, encapsulate each one, and making then interchangeable.
usage
The Strategy pattern is useful when there is a set of related algorithms and a client object needs to be able to dynamically pick and choose an altorithm form this set that suits its current need
-
-
Visitor
-
usage
provides you with a way to add new operations on the objects without changing the classes of the elements,especially when the operations change quite often
-
Structure Pattern
-
Composite
Definition
allow you to compose objects into a tree structure to represent the part-whole hierarchy which means you can create a tree of objects that is made of different parts, but that can be treated as a whole one big thing
-
when to use
-
When you want clients to be able to ignore the difference between compositions of objects and individual objects. Clients will treat all objects in the composite structure uniformly
-
Bridge
Definition
An abstraction defines the abstraction's interface and also maintains a reference to an object of type implementer, and the link between the abstraction and the implementer is called a Bridge.
-
usage
It put the abstraction and implementation into two different class hierarchies so that both can be extend independently
-
-
Adapter
-
usage
It converts the interface of a class into another interface the client expect. It let classed work together that couldn't otherwise because of incompatible interfaces.
when to use
there is an existing class, and its interface does not match the on you need
-
Facade
when to use
A facade can provide a simple default view of the subsystem that is good enough for most clients. Only clients nedding more customizability will need to look beyond the facade.
Introduce a facade to decouple the subsystem from clients and other sybsystems, thereby promoting sbsystem independence and portability.
-
-
-
Creational Pattern
-
Factory Method
Definition
define an interface for creating an object, but let subclasses decide which class to instantiate
-
when to use
-
-
Classed delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of whick helper subclass is the delegate
Prototype
Definition
is used to specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype
-
-
-
Abstract Factory
Definition
provide an interface for creating families of related or dependent objects without specifying their concrete classes
usage
provide an interface for creating families of related or dependent objects without specifying their concrete classes
when to use
A system should be independent of how its products are created, composed, and represented
A family of related product objects is designed to be used together, and you need to enforce this constrain
You want to provide a class library of products, and you want to reveal just their interfaces, not their implementations
Builder
Definition
The Builder pattern suggests moving the construction logic out of the object class to a separate class referred to as a builder calss
usage
The intent of the Builder Pattern is to separate the construction of a complex object from its representation, so that the same construction process can create different representations.
when to use
-
The algorithm for creating a complex object should be independent of the parts that make up the object and how they're assembled.