陳韋傑
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # The 23 Design Patterns by GoF ## Links - [The 23 well-known GoF design pattern](https://buihuycuong.medium.com/the-23-gang-of-four-design-patterns-974ae8d1a957) - [Design Pattern 系列文](https://waynecheng.coderbridge.io/2021/01/09/DesignPattern-Preface/) - [Design Pattern 鐵人賽](https://ithelp.ithome.com.tw/articles/10216587) 以下圖片來自 [大話設計模式](https://github.com/3masterplus/book/blob/master/%E5%A4%A7%E8%AF%9D%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F(%E5%B8%A6%E7%9B%AE%E5%BD%95%E5%AE%8C%E6%95%B4%E7%89%88).pdf)。 ## UML Class Diagram ![image](https://hackmd.io/_uploads/SyZg6VGG1l.png) ### Dependency (Use-a) - Briefly interacts, use its function and maybe only once - Do not hold reference ### Association (Has-a) - Mostly used - Association Qualifier (Hash Table, IRS + Tax ID <-> Person) - Hold a reference of each other, interact in a given period of time ### Aggregation (Owns-a, Your things -> You) - Recursive case: with base node - If one of them is missing, another might be unaffected - Actively Instantiate (Compared to Association) ### Composition (Is-part-of-a, Hand -> You) - Strong and seldomly used - If one of them is missing, then the other one will be missing as well - Need to be responsible for life cycle of its component ### Generalization (Is-a, Animal <- Cat) - Inheritance relationship ## Design Process from J Lee Encapsulation, Abstraction, Delegation ![image](https://hackmd.io/_uploads/Hyt9Pwx-Je.png) - Encapsulation: Encapsulate what varies - Abstraction: Program to an interface, not to implementation - Delegation: Depend on Abstraction, not on concrete class ## Introduction The Gang of Four (GoF) design patterns refer to the 23 design patterns introduced in the book "Design Patterns: Elements of Reusable Object-Oriented Software" by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. These patterns are categorized into three main groups based on their purpose: ## Categories 1. Creational Patterns: These patterns deal with the process of object creation, trying to make the creation process more flexible and dynamic. * Abstract Factory: Provides an interface for creating families of related or dependent objects without specifying their concrete classes. ![image](https://hackmd.io/_uploads/S1gZumzf1g.png) ![image](https://hackmd.io/_uploads/r1bf_mzGke.png) * Builder: Separates the construction of a complex object from its representation, allowing the same construction process to create different representations. ![image](https://hackmd.io/_uploads/r1W_D7fG1l.png) ![image](https://hackmd.io/_uploads/BJOKDmzGJl.png) * Factory Method: Defines an interface for creating objects, but lets subclasses alter the type of objects that will be created. ![image](https://hackmd.io/_uploads/H13QEQMf1x.png) ![image](https://hackmd.io/_uploads/HycVVmzfkg.png) * Prototype: Creates new objects by copying an existing object (the prototype). ![image](https://hackmd.io/_uploads/BkfaVQGGJg.png) ![image](https://hackmd.io/_uploads/r1paV7zfJl.png) * Singleton: Ensures that a class has only one instance and provides a global point of access to it. ![image](https://hackmd.io/_uploads/HJHp3QGM1l.png) ![image](https://hackmd.io/_uploads/SJnThQGMkx.png) 2. Structural Patterns: These patterns are concerned with the composition of classes or objects to form larger structures, focusing on how to ensure relationships between entities are maintained. * Adapter: Allows incompatible interfaces to work together by converting one interface to another that a client expects. ![image](https://hackmd.io/_uploads/Sy_iOmGfkl.png) ![image](https://hackmd.io/_uploads/SyEnuXfMyl.png) * Bridge: Decouples an abstraction from its implementation so that the two can vary independently. ![image](https://hackmd.io/_uploads/r1yHamzf1e.png) ![image](https://hackmd.io/_uploads/By6rTQfzke.png) * Composite: Composes objects into tree-like structures to represent part-whole hierarchies. ![image](https://hackmd.io/_uploads/H1SmYmGG1l.png) ![image](https://hackmd.io/_uploads/r1XVtmfMkg.png) * Decorator: Attaches additional responsibilities to an object dynamically, without affecting other objects of the same class. ![image](https://hackmd.io/_uploads/HyU1GXMfkl.png) ![image](https://hackmd.io/_uploads/SyLWf7zM1x.png) * Facade: Provides a simplified interface to a complex subsystem of classes. ![image](https://hackmd.io/_uploads/rJoGvXGz1x.png) ![image](https://hackmd.io/_uploads/BJPQvmfz1x.png) * Flyweight: Uses sharing to support large numbers of fine-grained objects efficiently. ![image](https://hackmd.io/_uploads/rkVlkVGM1g.png) ![image](https://hackmd.io/_uploads/Sk6gkNzMkx.png) * Proxy: Provides a surrogate or placeholder for another object to control access to it. ![image](https://hackmd.io/_uploads/r1HHzmMzyg.png) ![image](https://hackmd.io/_uploads/rJ1IfQzMyl.png) 3. Behavioral Patterns: These patterns are concerned with communication between objects, focusing on the interaction and responsibilities between them. * Chain of Responsibility: Allows a request to be passed along a chain of handlers until one of them handles it. ![image](https://hackmd.io/_uploads/SJHWCXzM1g.png) ![image](https://hackmd.io/_uploads/HJgzAmffyg.png) * Command: Encapsulates a request as an object, allowing parameterization of clients with queues, requests, and operations. ![image](https://hackmd.io/_uploads/BJKhTQGGkl.png) ![image](https://hackmd.io/_uploads/ryfaTXfzyg.png) * Interpreter: Implements a specialized language and interprets sentences of that language. ![image](https://hackmd.io/_uploads/rJNE1Eff1x.png) ![image](https://hackmd.io/_uploads/By-B1EfM1l.png) * Iterator: Provides a way to access elements of an aggregate object sequentially without exposing its underlying representation. ![image](https://hackmd.io/_uploads/HkRknXGz1l.png) ![image](https://hackmd.io/_uploads/ryCe27fMkg.png) * Mediator: Defines an object that controls how a set of objects interact, centralizing communication. ![image](https://hackmd.io/_uploads/ByLD07ffye.png) ![image](https://hackmd.io/_uploads/H1wdRmGfJe.png) * Memento: Captures the internal state of an object without exposing its implementation, allowing it to be restored later. ![image](https://hackmd.io/_uploads/rk7WFQfGyx.png) ![image](https://hackmd.io/_uploads/SJRbK7Gz1x.png) * Observer: Defines a one-to-many dependency, so when one object changes state, all its dependents are notified and updated automatically. ![image](https://hackmd.io/_uploads/BJYTD7zMkl.png) ![image](https://hackmd.io/_uploads/HJSy_QMGkg.png) * State: Allows an object to alter its behavior when its internal state changes, making it appear as if the object changed its class. ![image](https://hackmd.io/_uploads/Bk6QuXfM1x.png) ![image](https://hackmd.io/_uploads/Sy5V_XGzkx.png) * Strategy: Defines a family of algorithms, encapsulates each one, and makes them interchangeable. ![image](https://hackmd.io/_uploads/rJIygXfGJe.png) ![image](https://hackmd.io/_uploads/r1QXfmGz1g.png) * Template Method: Defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm. ![image](https://hackmd.io/_uploads/BJ76I7Mzyl.png) ![image](https://hackmd.io/_uploads/H16a87MzJe.png) * Visitor: Allows you to define new operations on elements of an object structure without changing the elements themselves. ![image](https://hackmd.io/_uploads/HyvF1EMzyg.png) ![image](https://hackmd.io/_uploads/B1_skVGfJg.png) ## Summary of GoF 23 Patterns * Creational Patterns: Deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. * Structural Patterns: Deal with the composition of classes and objects, focusing on how to make larger structures more flexible. * Behavioral Patterns: Deal with the interaction between objects, focusing on how responsibilities are distributed and how objects collaborate. These patterns provide well-established solutions for common design problems, making it easier to create reusable, maintainable, and scalable software systems. # SOLID * Single Responsibility Principle (SRP): A class should have only one reason to change, meaning it should only have one job or responsibility. ![image](https://hackmd.io/_uploads/SJCql7zG1e.png) * Open/Closed Principle (OCP): Software entities should be open for extension but closed for modification, allowing behavior changes without altering existing code. ![image](https://hackmd.io/_uploads/SkDaemMMyl.png) * Liskov Substitution Principle (LSP): Objects of a superclass should be replaceable with objects of a subclass without altering the correctness of the program. ![image](https://hackmd.io/_uploads/B17kbQfG1e.png) * Interface Segregation Principle (ISP): Clients should not be forced to depend on interfaces they do not use, favoring smaller, specific interfaces over large, general-purpose ones. * Dependency Inversion Principle (DIP): High-level modules should not depend on low-level modules; both should depend on abstractions to promote loose coupling. ![image](https://hackmd.io/_uploads/SJP0g7zGJg.png) # Others * Law of Demeter ![image](https://hackmd.io/_uploads/HJalw7Gfye.png) * Composition/Aggregate Reuse Principle (CARP) ![image](https://hackmd.io/_uploads/BJLgaQMGJe.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully