Showing posts with label Software Design. Show all posts
Showing posts with label Software Design. Show all posts

23 GOF Design Pattern

Creation Patterns

Structural Patterns
Behavioral Patterns
Reference:

Visitor Pattern

เป็นส่วนที่ไปทำงานบนระบบอื่น เพื่อให้ระบบอื่นเรียกใช้




Mediator Pattern




Interpreter Pattern

เป็นการแปลงข้อมูลจาก format หนึ่งไปยังอีก format หนึ่ง หรือการ convert ข้อมูล


ตัวอย่างของ Interpreter pattern เช่น parser, XML parser

Builder Pattern




Bridge Pattern

Bridge pattern will decouple an abstraction from its implementation so that the two can vary independently
แต่จะทำให้ระบบมีความซับซ้อนขึ้น และมี performance ต่ำลง แต่ว่าจะช่วยให้ระบบมีความยืดหยุ่นมากขึ้น



State Pattern

The State Pattern allows an object to alter its behavior when its internal state changes. The object will appear to change its class.




Proxy Pattern

โดยเมื่อก่อนใช้คำว่า Stub โดยมี Skeleton เป็น implementation หรือ object เป็นตัวที่ตรงกันข้ามกับ Facade คือเป็นตัวกั้นทางออก กั้น request จากภายในระบบกับระบบภายนอก




Template Pattern

เป็นการทำ template ไว้ให้เลย



Singleton Pattern

The Singleton Pattern ensures a clas has only one instance, and provides a global point of access to it.





Factory Pattern

The Factory Method Pattern defines an interface for creating an object, but lets subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.




The Abstract Factory Pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes.
Abstract Factory จะเป็น Interface สำหรับ Factory Class เพื่อให้ Factory Class ในระบบมี pattern เดียวกัน เช่น มีชื่อ Factory Method เดียวกัน




Facade Pattern

เป็นตัวกั้น request จากภายนอกที่จะเข้ามาเรียกการทำงานภายในระบบ



ตัวอย่างของ Facade pattern เช่น Front Controller ซึ่งเป็นตัวกั้น request จาก UI กับระบบภายใน

Decorator Pattern

The Decorator Pattern attaches additional reponsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.




Iterator Pattern




Composite Pattern

Compose objects into tree structures to represent part




Strategy Pattern

The Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
มักใช้ร่วมกันกับ Bridge pattern




Strategy Pattern เป็น pattern ที่เปลี่ยนแนวความคิดจากการใช้ Inheritance มาเป็น Composition แทนซึ่งมีความยืดหยุ่นกว่า และเป็น pattern ที่ใช้ในอีกหลายๆ pattern ด้วย

Design principle


  • Encapsulate what varies. - Identify the aspects of your application that vary and separate them from what stays the same.
  • Program to an interface, not an implementation.
  • Favor composition over inheritances.
  • Strive for loosely coupled designs between objects that interact.
  • Classes should be open for extension, but closed for modification.
  • Depend upon abstractions. Do not depend upon concrete classes.
  • Only talk to your friends.
  • Don't call us, we'll call you.
  • A class should have only one reason to change.

หรือในอีกมุมหนึ่งจะดูตามหัวข้อ

  • Communication Path and Access Channel 
    • Communication Path เป็นการกำหนดเส้นทางสือสารระหว่าง Element ต่างๆ
    • Access Channel เป็นการกำหนดการเข้าถึง Element
  • Coupling and Cohesion
  • Modularity คือการกำหนดหน้าที่ (method) และคุณสมบัติ (property) ให้โมดูลมีความสมบูรณ์ และมีความอิสระ ไม่พึ่งพาโมดูลอื่นๆ
  • Classification ต้องใช้ Design Principle หลายชนิด 
    • Association, Aggretation, Composition
    • Hierarchy, Generalization, Specialization
    • Packaging
  • Hierarchy, Generalization and Specialization
  • Information Hiding, Encapsulation and Abstraction
  • Contract, Boundary and Interface Design
  • Capability, Operation and Method
  • Dispatch and Delegate
  • Association, Aggregation and Composition


Reference: Head First Design Patterns - O'reilly