Giter Site home page Giter Site logo

design_patterns's Introduction

What is Design Patterns

Design patterns are like smart solutions for common problems in software design. They help improve code readability, maintainability, and scalability.

Here's a practical problem statement to understand the need for design patterns:

Let's say you're making a library app where people can borrow books. Each book can only be borrowed by one person at a time. You also want to keep track of who has which book and when it's due back.

Here's how design patterns can help:

You can use the Singleton pattern. It ensures there's only one BookManager class in the whole app. This class handles all the books and the borrowing process. It makes sure only one person can borrow a book at a time.

Also, you can use the Observer pattern. It helps notify users when a book they want is available for borrowing. It also reminds them when a book they've borrowed is due back.

By using these patterns, you make a system that's easy to understand, scale, and manage for your library app.

Types of Design Patterns:

These patterns focus on creating objects.

  • Abstract Factory : Helps create families of related objects without specifying their exact classes.
  • ⬜️ Builder : Makes it easier to create complex objects step by step.
  • ⬜️ Factory Method : Simplifies creating objects by letting subclasses decide which class to instantiate.
  • ⬜️ Prototype : Allows creating new objects by copying existing ones.
  • ⬜️ Singleton : Ensures only one instance of a class exists throughout the program.

These patterns organize classes and objects.

  • ⬜️ Adapter : Makes different interfaces work together smoothly.
  • ⬜️ Bridge : Separates abstraction from implementation.
  • ⬜️ Composite : Organizes objects into tree structures to represent part-whole hierarchies.
  • ⬜️ Decorator : Adds extra features to objects dynamically.
  • ⬜️ Facade : Provides a simplified interface to a complex system.
  • ⬜️ Flyweight : Helps save memory by sharing common parts of objects.
  • ⬜️ Proxy : Acts as a placeholder for another object, controlling access to it.

These patterns manage communication between objects.

  • ⬜️ Chain of Responsibility : Handles a request by passing it through a chain of objects.
  • ⬜️ Command : Encapsulates a request as an object, allowing parameterization of clients.
  • ⬜️ Interpreter : Helps interpret a language or syntax.
  • ⬜️ Iterator : Helps access elements of a collection without exposing its underlying structure.
  • ⬜️ Mediator : Reduces coupling between objects by introducing a mediator object.
  • ⬜️ Memento : Saves and restores an object's state.
  • ⬜️ Observer : Notifies multiple objects of any state changes.
  • ⬜️ State : Allows an object to change its behavior when its internal state changes.
  • ⬜️ Strategy : Encapsulates algorithms and makes them interchangeable.
  • ⬜️ Template Method : Defines the skeleton of an algorithm, letting subclasses override specific steps.
  • ⬜️ Visitor : Helps perform operations on a group of related objects without changing their classes.

License

This project is licensed under the MIT License - see the LICENSE file for details.

design_patterns's People

Contributors

rajaniket avatar

Watchers

 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.