Giter Site home page Giter Site logo

omarsamy3 / desgin-patterns Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 582 KB

This is a training repo to implement different kinds of design patterns for practicing.

C# 100.00%
creational-design-patterns creational-patterns design-pattern go4 problem-solving solid-principles

desgin-patterns's Introduction

Desgin-Patterns

This is a training repo to implement different kinds of design patterns for practicing.

Creational Patterns

1. Singleton Pattern..

  • To have only one instance of a class to provide more storage in memory.

By making a private constructor to prevent creating instances using constructor, and replace that with a function to deal with the same private instance in your class.
You can lock the creation of the instance in case of multithreading.

2.Prototype Pattern

  • Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.

Copy heavy initialization objects instead of creating it.
This helps to save time consuming to get data every time I want it -from database for example -.

3. Builder Pattern

  • Separate the construction of a complex object from its representation so that the same construction processes can create different representations.
    Build complex objects step by step ... Like string builder class.

Keep the class user away from the complex implementation of the object.

4. Factory Pattern

  • Define an interface for creating an object, but let subclasses decide which class to instantiate.
    Create object without exposing the creation logic to the client and refer to newly created object using a common interface.

Make an interface to be implemented by the different kinds of classes and to be used to make the loginc needed by another class with will make the required logic.

Abstract Factory Pattern

Make the Factory class deal with different classes to include their functions and call the facory object only one time to use for different cases.

Structural Patterns:-

1. Proxy Pattern

  • Provide a surrogate or placeholder for another object to control access to it. Like a gateway for an object

The client calls the proxy instead of web service, so if the service changed, we deal with the proxy not the client Remote Proxy
Get data from database using the proxy, and the client deal with the proxy not the database Virtual Proxy
Protect the object from the client to control it yourself away from the client Protection Proxy.

2. Decorator Pattern

Allows behavior to be added to an individual object, dynamically, without affecting the behavior of other objects from the same class.
The decorator pattern is often useful for adherting to the Single Resposiblity Principle,
as it allows functionality to be divided between classes with unique areas of concern.

3. Adapter Pattern

Convert the interface of a class into another interface that clients expect.
The Adapter pattern lets classes work together that could not otherwise because of incompatible interfaces.

4. Facade Pattern

Provide a unified interface to a set of interfaces in a subsystem.
Facade defines a higher-level interface that makes the subsystem easier to use.

5. Flyweight Pattern

Use sharing to support large numbers of fine-grained objects efficiently.
Flyweight lets you fit more objects into the available amount of RAM by sharing common parts of state between multiple objects instead of keeping all of the data in each object.

Behavioral Patterns:-

1. Chain of Responsibility Pattern (COR)

  • Can we make more than handler for a given request?
  • How can we handle a request using sequence of steps?

Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.
Chain the receiving objects and pass the request along the chain until an object handles it.

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.