Singleton Pattern

The singleton design pattern ensures that a class has only one instance and provides a global point of access to that instance. This pattern is often used when exactly one object is needed to coordinate actions across the system, such as when managing shared resources like databases or configuration settings. Motivation The singleton pattern is motivated by scenarios where certain classes should only be instantiated once. Common examples include: Database Connections: You typically only want one instance of a database connection throughout the lifecycle of an application to avoid redundant connections and ensure consistent access to the data....

August 26, 2024 · 7 min · 1414 words · Me

Solid Principles

Single Responsibility Principle (SRP) The Single Responsibility Principle (SRP) is one of the five SOLID principles of object-oriented design and programming. It states that a class, module, or function should have only one reason to change, meaning it should have only one responsibility or job. This principle promotes the idea that a class should only have one reason to exist, encapsulating all the functionality related to that responsibility. Key Points of Single Responsibility Principle...

August 26, 2024 · 11 min · 2256 words · Me