{"id":24794165,"url":"https://github.com/shubhamv108/object-oriented-design-patterns","last_synced_at":"2025-10-12T20:30:36.999Z","repository":{"id":186315945,"uuid":"181750479","full_name":"shubhamv108/object-oriented-design-patterns","owner":"shubhamv108","description":"Simple examples of some of the Object Oriented Design Patterns.","archived":false,"fork":false,"pushed_at":"2025-01-17T03:08:46.000Z","size":34500,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-17T04:18:43.984Z","etag":null,"topics":["abstract-factory-pattern","bridge-game","builder-pattern","chain-of-responsibility-pattern","command-pattern","factory-pattern","object-oriented","object-oriented-design","object-oriented-design-patterns","object-oriented-programming","observer-pattern","pipes-and-filters","pipes-and-filters-pattern","prototype-pattern","proxy-pattern","singleton-pattern","strategy-pattern","visitor-pattern"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shubhamv108.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-16T19:07:06.000Z","updated_at":"2025-01-17T03:08:48.000Z","dependencies_parsed_at":"2024-02-25T09:44:45.135Z","dependency_job_id":null,"html_url":"https://github.com/shubhamv108/object-oriented-design-patterns","commit_stats":null,"previous_names":["shubhamv108/object-oriented-design-patterns"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamv108%2Fobject-oriented-design-patterns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamv108%2Fobject-oriented-design-patterns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamv108%2Fobject-oriented-design-patterns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamv108%2Fobject-oriented-design-patterns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shubhamv108","download_url":"https://codeload.github.com/shubhamv108/object-oriented-design-patterns/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236268839,"owners_count":19121817,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abstract-factory-pattern","bridge-game","builder-pattern","chain-of-responsibility-pattern","command-pattern","factory-pattern","object-oriented","object-oriented-design","object-oriented-design-patterns","object-oriented-programming","observer-pattern","pipes-and-filters","pipes-and-filters-pattern","prototype-pattern","proxy-pattern","singleton-pattern","strategy-pattern","visitor-pattern"],"created_at":"2025-01-29T22:34:29.598Z","updated_at":"2025-10-12T20:30:29.932Z","avatar_url":"https://github.com/shubhamv108.png","language":"Java","readme":"## Refactoring\n    Remodelling overall app so that new features can fit up or you can optimize overall app for achieving readability, extensibility, ...\n\n## OOPS\n#### Abstraction\n    Display only essential information and hide details\n#### Encapsulation\n    Binding data and behaviour into single unit\n#### Polymorphism\n    Perform same thing in different ways\n#### Inheritance\n    Sub class inherits properties and methods from base class\n\n## Relations b/w classes\n    1. Association\n        - Biderictional relationship b/w classes\n        - 1 to *\n        - * to 1\n        - 1 to 1\n    2. Composition\n        - Part cannot exist without Whole\n    3. Aggregation\n        - Whole-Part relationship\n        - Class contains object of another class but contained object can exist independently\n    4. Generatlization\n        - IS A relationship\n        - like inheritance\n\n\n## SOLID\n- conventions \n- create maintainable, extensible, flexible s/w \n- SOLID principle provides/helps\n  - Testing\n  - Modularity\n  - Coupling\n### Single Responsibility Principle\n- A class should have only one reason/responsibility to change.\n- class adheres to SRP\n  - Identify responsibility\n  - Separation of concerns\n- Scenarios that violate SRP\n    - God class\n      - split into smaller classes handling single reposibility\n### Open-Closed Principle\n- A class should be open for extension but closed for modification\n- Example: Adapters for payment processors\n### Liskov-substitution\n- Base/Derieved class pointer should be interchangeable\n- object of super class should be easily replecable with object of subclass\n- subclass should preserve behavior of superclass\n- requires\n  - Behavorieal Presentation\n- Exmple: Adapters for payment processors\n### Interface seggregation\n- A class should not \"forced to\" implement interfaces or implement interface methods which it does not require\n- remove/avoid unnecessary dependencies\n- flexibility/dependencies\n- What should not do \n  - Avoid bloating\n- Example : saveCardDetails() require a seperate interface for Payment processor\n### Dependency Inversion\n- Use interface/abstract class for dependency rather concrete implementation\n- loose coupling\n- Flexible, easier to test, maintable\n- Example: Injecting Payment Processr Adapter into payment service. \n\n##### Inversion of control\n- \n\n## Design Patterns\n    - Typical solutions to commonly occurring problems in software design.\n    - Blueprints that can be used to customize to solve a particular design problem in your code.\n    - Well known way of solving a well known problem. (Template for solving problem)\n    - Simpler communication in one phrase\n\n### Object Oriented Design Patterns\n- Creational\n    \n    1.   [Builder](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/builder)\n          - Seperate construction of object from its representation.\n          - avoiding a constructor with numerous parameters\n          - Perform validations\n          - Creation of object is easier and resillient\n          - Director - any class orchestrates the construction process using builder interface to construct actual objects.\n          - Final objects return to client by Director\n          - complexity\n          - enhancement\n          - loose coupling\n          - extensibility\n    \n    2.   [Factory](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/factory)\n         - Segregating the logic for creating the object wherever required\n    \n    3.   [Prototype](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/prototype)\n         - Cloning of the object (based on the existing ones)\n         - Document Management system (clone document)\n         - DB entity (clone db entity)\n         - configuration management\n    \n    4.   [Singleton](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/singleton)\n         - Single object getting created throughout the scope of execution.\n         - Can achieve thread safety\n    5.   [Abstract Factory](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/abstractfactory)\n         - Interface for Factory of similar objects without concrete classes\n\n    6.   [Factory Method](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/factorymethod)\n    \n- Behavioral\n\n    7.   [Strategy](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/strategy)\n\n    8.   [Chain of Responsibility](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/chainofresponsibility)\n         - Allows an object to pass through a chain of handler.\n         - Handlers will decide either to process or pass the request to next handler.\n    \n    9.   [Command](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/command)\n         - Required when want to convert Actions/Requests/Methods into first class entity(object)\n         - Encapsulates the requests as an object which allows parameterization of client\n    \n    10.  [Observer](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/observer)\n         - For notifications\n         - Observer\n         - Observable\n         - One to Many relationship\n         - change in 1 leads to chnage in multiple\n         - without making tightly coupled\n         - dynamic chnages in number of observers and their types\n         - when to use\n           - Flexibilty \u0026 decoupling\n           - Real-Time updates\n           - Dynamic Relationships\n    \n    11. [Visitor](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/visitor)\n    \n    12. [Memento](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/memento)\n\n    13. [Pipes Filters](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/pipesfilters)\n\n    14. [Template Method](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/templatemethod)\n\n    15. [Iterator](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/iterator)\n\n    16. [Null Object](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/nullobject)\n \n    17. [Strategy](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/strategy)\n        - selecting algorithm or behaviour at runtime\n        - encourages composition over inheritance\n  \n    18. [State]()\n        - allow state change when behaviour is going to be chnaged\n        - encapsulation of the behavior associated with the state\n        - Behavior of a particular classes and entities\n        - deals with conditional aspects\n        - context - mantains current state of the object\n\n- Structural  \n    \n    19. [Adapter](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/adapter)\n        - Allows objects with incompatible interfaces to work together.\n        - Acting as a bridge b/w incompatible interfaces\n        - \"adpats\" the interface of one class to match interface of another class\n        - usability\n          - Integrate with 3rd party libraries or APIs\n          - Legacy System Interoperability\n          - Interface Standardization in Large Systems\n    \n    20. [Decorator](https://github.com/shubham-v/object-oriented-design-patterns/blob/main/src/main/java/decorator/Decorator.java)\n        - add additional responsibilities dynamically\n        - used with Inheritance\n        - used for Open Closed Principle\n        - maintains interface to pizza object\n        - Structure\n          - Component\n          - ConcreteComponent\n          - Decorator (Wrapper along with Reference to component)\n          - Concrete Decorator\n        - example: Pizza, Coffee, Premium subscription\n    \n    21. [Proxy](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/proxy)\n        - Placeholder to control and access another object without modifying the code\n        - lazy loading of object or initialization on demand\n        - control access. example security construct\n        - Usage \u0026 Usability\n          - Adding layer of control over real object\n          - lazy loading of expensive operation\n          - access control from the object\n        - Use cases\n          - Caching\n          - Logging\n          - Login\n\n    22. [Bridge](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/bridge)\n\n    23. [Flyweight](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/flyweight)\n  \n    24. [Facade](https://github.com/shubham-v/object-oriented-design-patterns/tree/main/src/main/java/facade/Facade.java)\n        - Way to hide complexity of a subsystem.\n        - \"Do not expose what is not necessary\" principle\n        - loose coupling\n        - high level user-friendly interface\n        - encourages encapsulation\n        - separation of concerns so that client have easiness to use the subsystem\n\n## Enums\n    Use when dealing FINITE set of things\n\n## Manager\n    POJO manager, if required\n\n## Status\n    - as a enum\n\n## Inheritance vs Composition\n    - In inheritance - bound to use everything as a part of subclass\n    - In composition - it is providing flixibility, encapsulation, easily extensible, easily modifiable, decoupled\n    - Composition avoids Diamond problem\n### Favour Composition Over Inheritance (FOI Principle)\n\n## Clean Code Practices\n    1.  Names of variables\n    2.\n    3.  Comments\n         eg. counter++; // Adding 1 to counter   X\n             counter++; // Incrementing counter\n    4.  Cormatting/Indentation\n    5.  Avoiding Magic numbers\n    6.  Exception\n    7.  Duplicate code avoiding (DRY)\n    8.  Single Responsibility principle\n    9.  Methods/Codebase should be small\n    10. Classes should be small\n    11. Clean/readable Unit test + cover all scenarios (very important)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshubhamv108%2Fobject-oriented-design-patterns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshubhamv108%2Fobject-oriented-design-patterns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshubhamv108%2Fobject-oriented-design-patterns/lists"}