Skip to content

souuzaa/DesignPattern

Repository files navigation

Design Pattern

Some examples to illustrate design pattern implementation
Book Reference: Head First: Design Patterns
Video Reference: Christopher Okhravi

Strategy Pattern

Definition: In computer programming, the strategy pattern (also known as the policy pattern) is a behavioral software design pattern that enables selecting an algorithm at runtime. The strategy pattern: -defines a family of algorithms, - each algorithm, and -makes the algorithms interchangeable within that family.
Ex: Calculate strategy (plus and minus example)
Reference:
https://www.youtube.com/watch?v=v9ejT8FO-7I
https://en.wikipedia.org/wiki/Strategy_pattern

Observer Pattern

Definition: The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.
Ex: Notify when attribute change
Reference:
https://www.youtube.com/watch?v=_BpmfnqjgzQ
https://en.wikipedia.org/wiki/Observer_pattern

Decorator Pattern

Definition: In object-oriented programming, the decorator pattern is a design pattern that allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class
Ex: Coffee shop, when we composite a coffe with addons
Reference:
https://www.youtube.com/watch?v=GCraGHx6gso
https://en.wikipedia.org/wiki/Decorator_pattern

Factory Method Pattern

Definition: In class-based programming, the factory method pattern is a creational pattern that uses factory methods to deal with the problem of creating objects without having to specify the exact class of the object that will be created.
Ex: Set Phone and Table prices using two differents factory
Reference:
https://www.youtube.com/watch?v=EcFVTgRHJLM
https://en.wikipedia.org/wiki/Factory_method_pattern

Abstract Factory Pattern

Definition: Same as Factory Method Pattern but we just use one factory to create two differents types
Ex: Set Phone and Table prices using the same factory
Reference:
https://www.youtube.com/watch?v=v-GiuMmsXj4
https://en.wikipedia.org/wiki/Abstract_factory_pattern

Singleton Pattern

Definition: The singleton pattern is a software design pattern that restricts the instantiation of a class to one object, we need to get instance of the object to use the object
Ex: Servlet
Reference:
https://www.youtube.com/watch?v=hUE_j6q0LTQ
https://en.wikipedia.org/wiki/Singleton_pattern

Command Pattern

Definition: The command pattern is a behavioral design pattern in which an object is used to encapsulate all information needed to perform an action or trigger an event at a later time.
Ex: Control lights house using "ON" and "OFF" commands
Reference:
https://www.youtube.com/watch?v=9qA5kw8dcSU
https://en.wikipedia.org/wiki/Command_pattern

Adapter Pattern (Wrapper)

Definition: The adapter pattern is a software design pattern (also known as Wrapper) that allows the interface of an existing class to be used as another interface
Ex: Chemical Components
Reference:
https://www.youtube.com/watch?v=2PKQtcJjYvc
https://en.wikipedia.org/wiki/Adapter_pattern

Facade Pattern

Definition: A facade is an object that provides a simplified interface to a larger body of code, such as a class library.
Ex: Creating a car structure (body, accessories, engine and model) using a facade class.
Reference:
https://www.youtube.com/watch?v=K4FkHVO5iac
https://en.wikipedia.org/wiki/Facade_pattern

Proxy Pattern

Definition: A proxy, in its most general form, is a class functioning as an interface to something else. -A proxy may hide information about the real object to the client. -A proxy may perform optimization like on demand loading. -A proxy may do additional house-keeping job like audit tasks.
Ex: A network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate.
Reference:
https://www.youtube.com/watch?v=NwaabHqPHeM
https://en.wikipedia.org/wiki/Proxy_pattern

About

Some examples to illustrate design pattern implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages