𝐖𝐡𝐚𝐭 𝐚𝐫𝐞 𝐃𝐞𝐬𝐢𝐠𝐧 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬 𝐢𝐧 𝐉𝐚𝐯𝐚?? > Design patterns are typical solutions to common problems in software design. They are like templates that can be applied to real-world programming situations to solve recurring design problems. > Design patterns can speed up the development process by providing tested, proven development paradigms. There are several types of design patterns: Creational, Structural, and Behavioral patterns. 𝟏. 𝐂𝐫𝐞𝐚𝐭𝐢𝐨𝐧𝐚𝐥 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬 These patterns provide ways to create objects while hiding the creation logic, rather than instantiating objects directly using a new operator. - **Singleton**: Ensures that a class has only one instance and provides a global point of access to it. - **Factory Method**: Defines an interface for creating an object, but lets subclasses alter the type of objects that will be created. - **Abstract Factory**: Provides an interface for creating families of related or dependent objects without specifying their concrete classes. - **Builder**: Separates the construction of a complex object from its representation so that the same construction process can create different representations. 𝟐. 𝐒𝐭𝐫𝐮𝐜𝐭𝐮𝐫𝐚𝐥 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬: These patterns deal with object composition or the way to compose objects to form larger structures. Structural patterns use inheritance to compose interfaces to obtain new functionalities. - Adapter: Allows objects with incompatible interfaces to work together by wrapping an interface around one of the existing objects. - Composite: Composes objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. - Decorator: Adds additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. - Facade: Provides a unified interface to a set of interfaces in a subsystem, making the subsystem easier to use. 𝟑. 𝐁𝐞𝐡𝐚𝐯𝐢𝐨𝐫𝐚𝐥 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬 These patterns are concerned with algorithms and the assignment of responsibilities between objects. - **Chain of Responsibility**: Passes a request along a chain of handlers. Each handler decides either to process the request or to pass it to the next handler in the chain. - **Iterator**: Provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation. - **Observer**: Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. - **Template Method**: Defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure. Understanding these patterns and knowing when and how to use them can greatly enhance your design and coding efficiency. #job #designpattern
Debjeet Roy’s Post
More Relevant Posts
-
Design Pattern: Factory Method Simple, but Powerful The Factory Method pattern stands out as a versatile solution for object creation and management. Imagine a scenario where you need to create instances of various types of objects, each with unique characteristics and behaviors. Traditionally, you might resort to direct instantiation within your code, leading to tightly coupled and inflexible structures. This is where the pattern shines. This pattern encapsulates object creation within a dedicated factory class, providing a centralized hub for generating objects of a specific family. This separation of concerns promotes loose coupling, making your code more adaptable and maintainable. Key Elements: - Factory Class: The orchestrator, responsible for creating and returning objects. - Factory Method: The core operation, defining the logic for object instantiation. Subclasses can override this method to customize object creation. - Concrete Product Classes: The individual object types produced by the factory. Benefits: - Promotes Loose Coupling: Decoupling object creation from specific code segments enhances flexibility and maintainability. - Centralizes Object Creation: Manages object generation in a single location, simplifying code organization and control. - Facilitates Subclass Customization: Subclasses can tailor object creation to their specific needs. Delphi Example: Consider a scenario where you need to create different types of buttons (e.g., Windows, Mac, Linux) for a graphical user interface. The Factory Method pattern can elegantly handle this task. interface type TButtonType = (btWindows, btMac, btLinux); IButton = Interface procedure Paint; end; TWindowsButton = class(TInterfacedObject, IButton) procedure Paint; end; TMacButton = class(TInterfacedObject, IButton) procedure Paint; end; TLinuxButton = class(TInterfacedObject, IButton) procedure Paint; end; TButtonFactory = class(TObject) function CreateButton(ButtonType: TButtonType): IButton; end; implementation function TButtonFactory.CreateButton(ButtonType: TButtonType): IButton; begin case ButtonType of btWindows: Result := TWindowsButton.Create; btMac: Result := TMacButton.Create; btLinux: Result := TLinuxButton.Create; end; end; { ... Button implementations ... } end. In this example, TButtonFactory serves as the factory class, encapsulating object creation. The CreateButton method determines the specific button type based on input and instantiates the corresponding object. This approach promotes loose coupling and facilitates customization for different button types. Conclusion: The Factory Method pattern stands as a valuable tool in the Delphi developer's arsenal, enabling efficient and flexible object creation mechanisms. Its ability to decouple object instantiation from application code enhances maintainability and promotes a well-structured codebase. #Delphi #DesignPatterns #FactoryMethod
To view or add a comment, sign in
-
** Design Patterns ** 𝐖𝐡𝐲 𝐃𝐞𝐬𝐢𝐠𝐧 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬 𝐌𝐚𝐭𝐭𝐞𝐫? [1.] Reusability ◾ reusable solutions that have been proven effective in numerous projects [2.] Flexibility ◾ promote loose coupling and adaptable designs, making software easier to maintain and extend [3.] Communication ◾ provide a shared vocabulary for discussing design issues and solutions [4.] Experience ◾ encapsulate the experience of seasoned developers, helping others avoid common pitfalls and design better software 📌 𝐂𝐫𝐞𝐚𝐭𝐢𝐨𝐧𝐚𝐥 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬 [1.] Abstract Factory ◾ creates families of related objects through a common interface ◾ promotes loose coupling [2.] Builder ◾ separates complex object construction from representation ◾ enables different representations with the same process [3.] Factory Method ◾ defines an interface for creating objects ◾ allows subclasses to choose the concrete class to instantiate [4.] Prototype ◾ creates new objects by copying a prototypical instance [5.] Singleton ◾ ensures a class has only one instance ◾ provides a global access point 📌 𝐒𝐭𝐫𝐮𝐜𝐭𝐮𝐫𝐚𝐥 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬 [6.] Adapter ◾ converts one interface to another, allowing incompatible classes to work together [7.] Bridge ◾ decouples abstraction and implementation, enabling independent variation [8.] Composite ◾ treats individual objects & their compositions uniformly, representing part-whole hierarchies [9.] Decorator ◾ dynamically adds responsibilities to an object without subclassing [10.] Facade ◾ provides a simplified interface to a complex subsystem [11.] Flyweight ◾ shares objects to reduce memory usage for large numbers of fine-grained objects [12.] Proxy ◾ controls access to an object, offering various capabilities like lazy loading or remote access 📌 𝐁𝐞𝐡𝐚𝐯𝐢𝐨𝐫𝐚𝐥 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬 [13.] Chain of Responsibility ◾ decouples request senders and receivers, allowing multiple objects to handle the request [14.] Command ◾ encapsulates requests as objects, enabling logging, queuing, and undo/redo operations [15.] Interpreter ◾ defines a grammar for a language and an interpreter to execute expressions [16.] Iterator ◾ provides sequential access to aggregate elements without exposing the underlying representation [17.] Mediator ◾ encapsulates object interaction, promoting loose coupling [18.] Memento ◾ captures and restores an object's state without violating encapsulation [19.] Observer ◾ notifies dependents automatically when an object's state changes [20.] State ◾ alters an object's behavior when its internal state changes [21.] Strategy ◾ encapsulates interchangeable algorithms, allowing clients to choose dynamically [22.] Template ◾ defines the skeleton of an algorithm, deferring steps to subclasses [23.] Visitor ◾ adds new operations to object structures without modifying the element classes #softwaredevelopment
To view or add a comment, sign in
-
Differences between #SOLID and #GOF Design Patterns SOLID and GOF (Gang of Four) Design Patterns both provide guidelines for designing robust, maintainable, and flexible software, but they approach this from different angles. 1. SOLID Principles: SOLID is a set of five core principles for object-oriented design introduced by Robert C. Martin (Uncle Bob). These principles focus on making software easier to maintain, extend, and adapt over time. The five SOLID principles: S: Single Responsibility Principle (SRP) A class should have only one reason to change, meaning it should have only one job or responsibility. O: Open/Closed Principle (OCP) Classes should be open for extension but closed for modification. This means you should be able to add new functionality without changing existing code. L: Liskov Substitution Principle (LSP) Objects of a subclass should be replaceable with objects of the superclass without affecting the correctness of the program. I: Interface Segregation Principle (ISP) Clients should not be forced to depend on interfaces they do not use. Interfaces should be small and specific to avoid "fat" interfaces. D: Dependency Inversion Principle (DIP) High-level modules should not depend on low-level modules. Both should depend on abstractions, and abstractions should not depend on details. 2. GOF Design Patterns: The Gang of Four (GOF) refers to a group of four authors who wrote the book "Design Patterns: Elements of Reusable Object-Oriented Software". They introduced 23 design patterns that provide proven solutions to common design problems in object-oriented systems. Examples of GOF Design Patterns: Creational Patterns: Deal with object creation. Factory Method, Singleton, Abstract Factory Structural Patterns: Deal with the composition of classes or objects to form larger structures. Adapter, Decorator, Facade Behavioral Patterns: Deal with communication between objects. Observer, Strategy, Command Key Differences: SOLID focuses on general principles for writing clean, maintainable, and scalable code. It provides a guideline on how to structure your code to reduce complexity, avoid rigid dependencies, and promote good object-oriented design. GOF Design Patterns are predefined solutions to specific, recurring problems in software design. They provide templates that you can follow when faced with common design challenges. Summary: SOLID is about high-level principles for writing well-structured, flexible code. GOF Design Patterns provide ready-made solutions to specific, well-known design problems. In practice, you can apply SOLID principles to help you design software that is modular and adaptable, and use GOF Design Patterns as building blocks to solve common architectural challenges. They complement each other in the development process.
To view or add a comment, sign in
-
🌟 Understanding the Factory Design Pattern 🌟 Hello LinkedIn community, As developers, we often encounter situations where creating objects directly using the new keyword can lead to code that's tightly coupled and hard to manage. This is where design patterns come into play, providing us with tested, proven development paradigms. One such powerful pattern is the Factory Design Pattern. 🏭 🔧 What is it? The Factory Design Pattern is a creational pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created. It helps in achieving loose coupling and ensures that the instantiation of objects is centralized, making our code more modular and easier to maintain. 🔑 Key Benefits: Encapsulation of Object Creation: The object creation code is isolated in a factory class, keeping it separate from the business logic. Scalability: It's easier to introduce new types of objects without changing the existing code. Enhanced Readability: Code becomes more readable and understandable. Loose Coupling: The pattern promotes loose coupling between the client code and the classes it instantiates. 💡 Use Cases: When the exact type of object isn’t known until runtime. When a class uses its subclasses to specify which objects to create. To avoid tight coupling between the client and the concrete classes. Here's a simple example to illustrate the Factory Design Pattern: // Product interface public interface IProduct { void DoSomething(); } // Concrete Products public class ProductA : IProduct { public void DoSomething() { Console.WriteLine("Product A"); } } public class ProductB : IProduct { public void DoSomething() { Console.WriteLine("Product B"); } } // Creator class with Factory Method public abstract class Creator { public abstract IProduct FactoryMethod(); public void SomeOperation() { var product = FactoryMethod(); product.DoSomething(); } } public class ConcreteCreatorA : Creator { public override IProduct FactoryMethod() { return new ProductA(); } } public class ConcreteCreatorB : Creator { public override IProduct FactoryMethod() { return new ProductB(); } } // Client code public class Client { public void Main() { Creator creatorA = new ConcreteCreatorA(); creatorA.SomeOperation(); Creator creatorB = new ConcreteCreatorB(); creatorB.SomeOperation(); } } As we continuously strive for writing clean, maintainable, and scalable code, understanding and implementing design patterns like the Factory Design Pattern becomes crucial. Feel free to share your experiences or ask any questions in the comments! Let's keep the discussion going. 🚀 #SoftwareEngineering #DesignPatterns #FactoryPattern #CleanCode #ScalableCode #Programming
To view or add a comment, sign in
-
Here are brief descriptions of commonly used design patterns (26): Creational Patterns: They are used during object creations. 1. Singleton: Ensures a single instance of a class exists. 2. Builder: Bypasses optional parameters in constructors. 3. Factory: Selects specific instances from subclasses based on input. 4. Abstract Factory: Creates families of related or dependent objects. It's a factory of factories and used to share common code using template pattern. 5. Prototype: Duplicates objects. 6. Object Pool: Manages a pool of reusable objects. Structural Patterns: Simplify the design of large object structures by identifying relationships between them. 1. Adapter: Makes one interface work with another. Used when we need to use one interface inside another interface's implementation to make them compatible. 2. Bridge: Decouples abstraction from implementation. Used when we've hierarchies in both interfaces as well as implementations. 3. Decorator (Wrapper): Adds behavior to objects via nested constructor calls. 4. Composite: Constructs tree-like structures of objects. 5. Facade: Provides a simplified interface to a complex system. 6. Flyweight: Shares objects to reduce memory usage. 7. Filter (Criteria): Chains criteria to filter objects. 8. Proxy: Controls access to objects. Behavioral Patterns: Concerned with communication between objects. 1. Chain of Responsibility: Passes requests through a chain of handlers. 2. Command (Action/Transaction): Encapsulates actions as objects. 3. Iterator: Sequentially accesses elements of a collection. 4. Interpreter: Evaluates expressions against input data. Used to encapsulate actions as objects, allowing for the execution of a list of actions with different implementations. 5. Mediator: Reduces complexity between objects. 6. Memento: Restores an object's state and maintain a history of states. 7. Null Object: Provides default behavior for null objects 8. Observer: Notifies dependent objects of state changes 9. State: Alters object behavior based on state. The behavior of the context object changes depending on its state 10. Strategy: Selects algorithms at runtime. The behavior of the context object changes depending on its strategy interface method. 11. Template Method: Defines the skeleton of an algorithm. It allows subclasses to redefine certain steps of the algorithm without changing its structure. 12. Visitor: Executes operations on elements of an object structure. Execution algorithm of element class can vary as and when visitor varies. These patterns help simplify design, improve code structure, and enhance maintainability. Here are the links of my github repositories consisting of various design patterns implementations using python and java: 1. Python https://lnkd.in/guMnMs_X 2. Java https://lnkd.in/g9uD5r7c #softwaredevelopment #softwareengineering #applicationdevelopment #designpatterns #lowleveldesign #systemdesign
To view or add a comment, sign in
-
Understanding the Power of Factory Patterns: Abstract Factory and Factory Pattern Factory patterns are a fundamental concept in software design, providing an elegant solution for creating objects without specifying the exact class of object that will be created. Let explore their definitions, benefits, and practical examples to understand and master these powerful design patterns. Factory Pattern The Factory Pattern is a creational design pattern that provides an interface for creating objects without exposing the underlying logic of object creation. It allows you to create objects without specifying the exact class of object that will be created. Structure: - Product: The base class or interface for the objects being created. - ConcreteProduct: The concrete classes that implement the Product interface. - Factory: The class that creates objects without specifying the exact class. - Client: The class that uses the Factory to create objects. Example: Suppose we have a `Vehicle` class with concrete subclasses `Car` and `Motorcycle`. We can create a `VehicleFactory` that creates instances of `Car` or `Motorcycle` based on a given type. Abstract Factory Pattern The Abstract Factory Pattern is a creational design pattern that provides an interface for creating families of related objects without specifying their concrete classes. It allows you to create objects that are part of a larger framework or library without exposing the underlying logic of object creation. Structure: - AbstractFactory: The interface that defines the methods for creating objects. - ConcreteFactory: The concrete classes that implement the AbstractFactory interface. - AbstractProduct: The base class or interface for the objects being created. - ConcreteProduct: The concrete classes that implement the AbstractProduct interface. - Client: The class that uses the AbstractFactory to create objects. Example: Suppose we have a `UIFactory` that creates objects for a graphical user interface. We can have concrete factories `WinUIFactory` and `MacUIFactory` that create platform-specific objects like `Window`, `Button`, and `TextField`. Benefits - Encapsulation: Factory patterns encapsulate object creation, making it easier to change or replace the underlying logic. - Polymorphism: Factory patterns allow for polymorphic object creation, making it easier to work with different types of objects. - Extensibility: Factory patterns make it easier to add new types of objects or factories without modifying existing code.
To view or add a comment, sign in
-
Great Insight on Design Pattern
If you want to learn Design Patterns and LLD, just watch these 11 Videos: These are the most important design Patterns that one can be asked during an interview. Singleton Design Pattern (Ensure a class has only one instance and provide a global point of access to it): https://lnkd.in/gh5uFq5p Factory Design Pattern (Define an interface for creating an object, but let subclasses alter the type of objects that will be created): https://lnkd.in/ghqAbVuW Composite Design Pattern (Compose objects into tree structures to represent part-whole hierarchies): https://lnkd.in/gDuW9BqP Builder Design Pattern (Use for Building immutable Objects): https://lnkd.in/gdgRrZSR State Design Pattern (Allow an object to alter its behavior when its internal state changes): https://lnkd.in/g4ez-Ubn Observer Design Pattern (Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically): https://lnkd.in/gKucwt-e Iterator Design Pattern (Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation): https://lnkd.in/gcPB_N6V Adapter Design Pattern (Convert the interface of a class into another interface clients expect): https://lnkd.in/gTg_fBy8 Strategy Design Pattern (Define a family of algorithms, encapsulate each one, and make them interchangeable): https://lnkd.in/gk9JUmYc Abstract Design Pattern (Provide an interface for creating families of related or dependent objects without specifying their concrete classes): https://lnkd.in/gvQ2Jhhm Prototype Design Pattern (Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype): https://lnkd.in/gFkBv7we Bonus: GitHub Repo that has Code examples of above Design Patterns: https://lnkd.in/gr8mr-J8 --- If you liked this post. 🔔 Follow: Shubham Sharma ♻ Repost to help others find it. 💾 Save it for future reference. #systemdesign #jobhelp #resources #learningeveryday #linkedinlearning
To view or add a comment, sign in
-
If you want to learn Design Patterns and LLD, just watch these 11 Videos: These are the most important design Patterns that one can be asked during an interview. Singleton Design Pattern (Ensure a class has only one instance and provide a global point of access to it): https://lnkd.in/gh5uFq5p Factory Design Pattern (Define an interface for creating an object, but let subclasses alter the type of objects that will be created): https://lnkd.in/ghqAbVuW Composite Design Pattern (Compose objects into tree structures to represent part-whole hierarchies): https://lnkd.in/gDuW9BqP Builder Design Pattern (Use for Building immutable Objects): https://lnkd.in/gdgRrZSR State Design Pattern (Allow an object to alter its behavior when its internal state changes): https://lnkd.in/g4ez-Ubn Observer Design Pattern (Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically): https://lnkd.in/gKucwt-e Iterator Design Pattern (Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation): https://lnkd.in/gcPB_N6V Adapter Design Pattern (Convert the interface of a class into another interface clients expect): https://lnkd.in/gTg_fBy8 Strategy Design Pattern (Define a family of algorithms, encapsulate each one, and make them interchangeable): https://lnkd.in/gk9JUmYc Abstract Design Pattern (Provide an interface for creating families of related or dependent objects without specifying their concrete classes): https://lnkd.in/gvQ2Jhhm Prototype Design Pattern (Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype): https://lnkd.in/gFkBv7we Bonus: GitHub Repo that has Code examples of above Design Patterns: https://lnkd.in/gr8mr-J8 --- If you liked this post. 🔔 Follow: Shubham Sharma ♻ Repost to help others find it. 💾 Save it for future reference. #systemdesign #jobhelp #resources #learningeveryday #linkedinlearning
To view or add a comment, sign in
-
𝐄𝐧𝐡𝐚𝐧𝐜𝐢𝐧𝐠 𝐒𝐤𝐢𝐥𝐥𝐬 𝐨𝐧 𝐂𝐫𝐞𝐚𝐭𝐢𝐨𝐧𝐚𝐥 𝐃𝐞𝐬𝐢𝐠𝐧 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬 I’ve recently completed a course on 𝐂𝐫𝐞𝐚𝐭𝐢𝐨𝐧𝐚𝐥 𝐃𝐞𝐬𝐢𝐠𝐧 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬. In this post I will share my learnings with detail explanation of each pattern. 𝐂𝐫𝐞𝐚𝐭𝐢𝐨𝐧𝐚𝐥 𝐃𝐞𝐬𝐢𝐠𝐧 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬 - It provides various object creation mechanisms, which increase flexibility and reuse of existing code. It help in making a system independent of how its objects are created, composed, and represented. 𝐓𝐲𝐩𝐞𝐬 𝐨𝐟 𝐂𝐫𝐞𝐚𝐭𝐢𝐨𝐧𝐚𝐥 𝐃𝐞𝐬𝐢𝐠𝐧 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬: 1. 𝐅𝐚𝐜𝐭𝐨𝐫𝐲 𝐌𝐞𝐭𝐡𝐨𝐝: - 𝐏𝐮𝐫𝐩𝐨𝐬𝐞: It provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created. This pattern is helpful when it’s necessary to separate the construction of an object from its implementation - 𝐖𝐡𝐞𝐧 𝐭𝐨 𝐔𝐬𝐞: 1. When we want flexibility in the instantiation of subclasses. 2. When we expect that our codebase will need to support new types in the future without requiring major changes to existing code 2. 𝐀𝐛𝐬𝐭𝐫𝐚𝐜𝐭 𝐅𝐚𝐜𝐭𝐨𝐫𝐲 - 𝐏𝐮𝐫𝐩𝐨𝐬𝐞: It is almost similar to Factory Pattern and is considered as another layer of abstraction over factory pattern. It provides an interface for creating families of related or dependent objects without specifying their exact concrete classes - 𝐖𝐡𝐞𝐧 𝐭𝐨 𝐔𝐬𝐞: 1. When you need to ensure related objects are used together 2. When your code needs to work with various families of related products, but don’t want it to depend on the concrete classes of those products extensibility. 3. 𝐁𝐮𝐢𝐥𝐝𝐞𝐫 - 𝐏𝐮𝐫𝐩𝐨𝐬𝐞: It lets you construct complex objects step by step. This pattern allows you to produce different types and representations of an object using the same construction code. - 𝐖𝐡𝐞𝐧 𝐭𝐨 𝐔𝐬𝐞: 1. To get rid of a “telescoping constructor”. 2. When we want our code to be able to create different representations of some product 4. 𝐏𝐫𝐨𝐭𝐨𝐭𝐲𝐩𝐞 - 𝐏𝐮𝐫𝐩𝐨𝐬𝐞: It allows you to create new objects by copying an existing object without making your code dependent on their classes. - 𝐖𝐡𝐞𝐧 𝐭𝐨 𝐔𝐬𝐞: 1. When the cost of creating an object is high, and there are many similar objects needed. 2. When you need many similar objects with slight differences, it’s often easier and more efficient to clone a prototype and modify it. 5. 𝐒𝐢𝐧𝐠𝐥𝐞𝐭𝐨𝐧 - 𝐏𝐮𝐫𝐩𝐨𝐬𝐞: It ensures a class has only one instance and provides a global point of access to that instance. - 𝐖𝐡𝐞𝐧 𝐭𝐨 𝐔𝐬𝐞: 1. When only one instance of a class is required to manage a shared resource (e.g., logging, database connection). 2. when we need stricter control over global variables I’m looking forward to using these patterns in my day-to-day work! For more details and examples visit my Github Page - https://lnkd.in/gWz3Gdwq . Thank you for reading.
To view or add a comment, sign in
-
17 Important Design Patterns. 👇 ⭐ 𝐂𝐫𝐞𝐚𝐭𝐢𝐨𝐧𝐚𝐥 𝐃𝐞𝐬𝐢𝐠𝐧 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬 ◾Singleton Pattern -Ensure a class has only one instance and provide a global point of access to it. ◾Factory Method Pattern -Define an interface for creating an object but let subclasses alter the type of objects that will be created. ◾Builder Pattern -Separate the construction of a complex object from its representation so that the same construction process can create different representations. ◾Prototype Pattern -Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype. ⭐ 𝐒𝐭𝐫𝐮𝐜𝐭𝐮𝐫𝐚𝐥 𝐃𝐞𝐬𝐢𝐠𝐧 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬 ◾Adapter Pattern -Convert the interface of a class into another interface clients expect. -Classes work together that couldn't otherwise because of incompatible interfaces. ◾Bridge Pattern -Decouple an abstraction from its implementation so that the two can vary independently. -Avoid permanent binding between an abstraction & its implementation. ◾Composite Pattern -Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. ◾Decorator Pattern -Attach additional responsibilities to an object dynamically. -When you want to add or alter the behavior of objects without altering their code. ◾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. ◾Flyweight Pattern -Use sharing to support a large number of fine-grained objects efficiently. ◾Proxy Pattern -Provide a surrogate or placeholder for another object to control access to it. ⭐ 𝐁𝐞𝐡𝐚𝐯𝐢𝐨𝐫𝐚𝐥 𝐃𝐞𝐬𝐢𝐠𝐧 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬 ◾Chain of Responsibility Pattern -Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. ◾ Command Pattern -Encapsulate a request as an object, thereby parameterizing clients with queues, requests, and operations. -When you want to decouple the sender and receiver of a request. ◾Mediator Pattern -Define an object that encapsulates how a set of objects interact. -Mediator promotes loose coupling by keeping objects from referring to each other explicitly. ◾Observer Pattern -Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. ◾State Pattern -Allow an object to alter its behavior when its internal state changes. The object will appear to change its class. ◾Strategy Pattern -Define a family of algorithms, encapsulate each one, and make them interchangeable. -Strategy lets the algorithm vary independently from clients that use it. Liked the humor in the image? Any funny/interesting interview experience you want to share? 😅😊 _____ 📌 Follow Mayank Ahuja, for regular Software Development insights. #softwaredevelopment
To view or add a comment, sign in