Skip to content

huynhdieutuong/DesignPatterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

I. Design Patterns

1. Creational Patterns

Factory method

Factory method - defines an interface for creating an object, but lets subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. Factory Method UML Pizza diagram

Abstract factory

Abstract factory - provides an interface for creating families of related or dependent objects without specifying their concrete classes. Factory Method UML Pizza diagram

2. Structural

Decorator

Decorator - attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. Decorator UML Duck diagram

Adapter

Adapter - converts the interface of a class into another interface the client expect. Adapter lets classes work together that coun't otherwise because of incompatible interfaces. Object adateprs and class adapters (composition vs ingeritance). Here is the Object Adapter UML: Adapter UML TurkeyAdapter diagram

Facade

Facade - provide a unified interface to a set of interfaces in a subsytem. Facade defines a higher-level interface that makes the subsystem easier to use. Object adateprs and class adapters (composition vs ingeritance). Here is the Object Adapter UML: Facade UML HomeTheater diagram

The Principle of Least Knowledge talk only to your immediate friends. Image Image1 Image2

Composite

Composite - compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. Composite UML Menus diagram

3. Behavioral

Strategy

Strategy - defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it. Strategy UML Duck diagram

State

State - allow an object to alter its behavior when its internal state changes. The object will appear to change its class. State UML Gumball Machine diagram

Observer

Observer - defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. Observer UML WeatherData diagram

Command

Command - encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations. Command UML Remote diagram Remote image Remote image

Template Method

Template method - defines 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. Template Method UML CaffeineBeverage diagram

Iterator

Iterator - provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation. Iterator UML Menus diagram

II. SOLID

1. Single Responsibility

  • Decorator
  • Factory Method
  • Abstract Factory
  • Command
  • Adapter
  • State

2. Open for Extension / Closed for Modification

  • Strategy
  • Observer
  • Decorator
  • Factory Method
  • Abstract Factory
  • Command
  • Adapter
  • State

3. Liskov Substitution

4. Interface Segregation

5. Dependency Inversion

III. OO Principles

  • Encapsulate what varies
  • Favor composition over inheritence
  • Program to interfaces, not implementations
  • Strive for loosely coupled designs between objects that interact
  • Classes should be open for extension but closed for modification
  • Depend on abstractions. Do not depend on concrete classes
  • Only talk to your friends (The Principle of Least Knowledge)
  • Don't call us, we'll call you (Hollywood Principle)
  • A class should have only one reason to change

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published