Skip to content

Instantly share code, notes, and snippets.

@neenjaw
Last active January 7, 2025 17:45
Show Gist options
  • Select an option

  • Save neenjaw/ecee7a49ca3caddf13ebe5e5c32a2986 to your computer and use it in GitHub Desktop.

Select an option

Save neenjaw/ecee7a49ca3caddf13ebe5e5c32a2986 to your computer and use it in GitHub Desktop.

Revisions

  1. neenjaw revised this gist Apr 12, 2021. 1 changed file with 24 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions notes_for_dive_design_patterns.md
    Original file line number Diff line number Diff line change
    @@ -28,6 +28,30 @@

    #### Factory Method

    - Provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that are created.
    - Delegate object creation to a factory class
    - Different objects related to a common interface

    ##### Applicability

    - Use Facotry Method when you don't know beforehand the exact types and dependencies of the objects your code should work with.
    - Use the Factory Method when you want to provide users of your library or framework with a way to extend its internal components.
    - Use the Factory Method when you want to save system resources by reusing existing objects instead of rebuilding them each time.

    ##### How to Implement

    1. make all products follow the same interface. This interface should eclare methods that make sense in every product.
    2. Add an empty factory method inside the creator class. The return type of the method should match the common product interface.
    3. Move object creation inside of the factory method, replacing the constructor call with the method call.
    4. Create set of creator subclasses for each type of product listed in the factory method, moving creation code

    ##### Pros-Cons

    - (+) avoid tight coupling
    - (+) _single responsibility principle_
    - (+) _open/closed principle_
    - (-) code complexity

    #### Abstract Factory
    #### Builder
    #### Prototype
  2. neenjaw revised this gist Apr 4, 2021. 1 changed file with 38 additions and 1 deletion.
    39 changes: 38 additions & 1 deletion notes_for_dive_design_patterns.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,38 @@
    # Notes for Dive Into Design Patterns
    # Notes for Dive Into Design Patterns

    ## Pillars of OOP

    - Abstraction
    - Polymorphism
    - Encapsulation
    - Inheritance

    ## Relations Between Objects

    - Dependency (dotted line, arrow) - some change to one might result in changes to another
    - Association (solid line, arrow) - one object uses or interacts with another
    - Aggregation (open diamond, solid line, arrow) - one-to-many, many-to-many, or whole-part relation
    - Composistion (solid diamond, solid line, arrow) - specific aggregation one obj is composed with another

    ## SOLID Principles

    - S - Single Responsibility Principle
    - O - Open/Closed - open for extension, closed for modification
    - L - Liskov Substitution Principle
    - I - Interface Segregation Principle
    - D - Depenency Inversion Principle

    ## Types

    ### Creational patterns

    #### Factory Method

    #### Abstract Factory
    #### Builder
    #### Prototype
    #### Singleton

    ### Structural patterns
    ### Behavioral patterns

  3. neenjaw created this gist Apr 4, 2021.
    1 change: 1 addition & 0 deletions notes_for_dive_design_patterns.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    # Notes for Dive Into Design Patterns