Giter Club home page Giter Club logo

design-patterns's Introduction

Design-Patterns

Factory Pattern

its one of a Creational Patterns which consist of:

  • Factory: which creates objects.
  • Protocol: which defines the methods that the products should implement.
  • Products: the objects that are created
UML Digram's Example:

Builder Pattern

its one of the Creational Patterns which consist of:

  • Product: which is a complex object to be created.
  • Builder: accepts step by step inputs and handle the creation of product.
  • Director: accepts inputs and coordinates with the builder.
UML Digram's Example:

Delegation Pattern

its one of a Behavioral Patterns because it's all about objects communication[one-to-one] which consist of three parts:

  • Delegating object: It’s the object that has a delegate. The delegate is usually held as a weak property to avoid a retain cycle.
  • Delegate protocol: which defines the methods that the delegate should implement.
  • Delegate: This is the helper object that implements the delegate protocol.

Example 1 UML Digram:
which represents communication between View Controller and its Service

Example 2 UML Digram:
which represents communication between View Controller and Presenter

Adapter Pattern

its one of a Behavioral Patterns which consist of four parts:

  • Client: Object using an adapter and depends on the protocol
  • protocol: which defines the methods we need
  • Adaptee/legacy object: cannot be modified directly so we need add extension or create new adapter
  • adapter: which helps us to make the incompatible objects deal with each other

UML Digram's Example:

protocol Target {
    func request()
}

class Adaptee {
    func specificRequest() {
        print("Specific request")
    }
}

class Adapter: Target {
    private let adaptee: Adaptee

    init(adaptee: Adaptee) {
        self.adaptee = adaptee
    }

    func request() {
        adaptee.specificRequest()
    }
}

let adaptee = Adaptee()
let adapter = Adapter(adaptee: adaptee)

adapter.request() // Prints "Specific request"

design-patterns's People

Contributors

hagerelsayed avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.