{"id":18258875,"url":"https://github.com/akazad13/csharp-design-patterns","last_synced_at":"2026-02-25T21:03:19.466Z","repository":{"id":247103321,"uuid":"821474753","full_name":"akazad13/csharp-design-patterns","owner":"akazad13","description":"Implementations of different design patterns","archived":false,"fork":false,"pushed_at":"2024-10-19T17:50:28.000Z","size":39,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T17:47:10.764Z","etag":null,"topics":["abstract-factory-pattern","adapter-pattern","behavioral-design-patterns","creational-design-patterns","csharp","decorator-pattern","design-patterns","facade-pattern","factory-pattern","singleton-pattern","structural-design-patterns"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akazad13.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2024-06-28T16:11:10.000Z","updated_at":"2024-10-19T17:50:32.000Z","dependencies_parsed_at":"2024-08-20T15:45:13.900Z","dependency_job_id":"d4ea0633-e927-488d-a8a3-42f0250a2498","html_url":"https://github.com/akazad13/csharp-design-patterns","commit_stats":null,"previous_names":["akazad13/csharp-design-patterns"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akazad13%2Fcsharp-design-patterns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akazad13%2Fcsharp-design-patterns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akazad13%2Fcsharp-design-patterns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akazad13%2Fcsharp-design-patterns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akazad13","download_url":"https://codeload.github.com/akazad13/csharp-design-patterns/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248483579,"owners_count":21111484,"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","adapter-pattern","behavioral-design-patterns","creational-design-patterns","csharp","decorator-pattern","design-patterns","facade-pattern","factory-pattern","singleton-pattern","structural-design-patterns"],"created_at":"2024-11-05T10:35:10.878Z","updated_at":"2026-02-25T21:03:14.431Z","avatar_url":"https://github.com/akazad13.png","language":"C#","readme":"# Design Patterns\n\n- [Creational Patterns](#creational-patterns)\n  - [Singleton](#singleton)\n  - [Factory Method](#factory-method)\n  - [Abstract Factory](#abstract-factory)\n  - [Builder](#builder) :soon:\n  - [Prototype](#prototype) :soon:\n- [Structural Patterns](#structural-patterns)\n  - [Adapter](#adapter) :soon:\n  - [Bridge](#bridge) :soon:\n  - [Decorator](#decorator) :soon:\n  - [Composite](#composite) :soon:\n  - [Facade](#facade) :soon:\n  - [Proxy](#proxy) :soon:\n  - [Flyweight](#flyweight) :soon:\n- [Behavioral Patterns](#behavioral-patterns)\n  - [Template](#template) :soon:\n  - [Strategy](#strategy) :soon:\n  - [Command](#command) :soon:\n  - [Momento](#momento) :soon:\n  - [Mediator](#mediator) :soon:\n  - [Chain of Responsibility](#chain-of-responsibility) :soon:\n  - [Observer](#observer) :soon:\n  - [State](#state) :soon:\n  - [Iterator](#iterator) :soon:\n  - [Visitor](#visitor) :soon:\n  - [Interpreter](#interpreter) :soon:\n  - [Repository](#repository) :soon:\n  - [Unit of Work](#unit-of-work) :soon:\n \n\n## Creational Patterns\n\nThese patterns deal with object creation.\n- Abstract the object instantiation process.\n- Help us make your system independent of how its object is created, composed, and represented.\n\n### Singleton\n\nSingleton lets you access your object from anywhere in your application. It guarantees that only one instance of this class will be available a time.\n\nHolding the class instance in a global variable doesn’t prevent clients from creating other instances of the class. We need to make the class responsible for ensuring only one instance of itself exists.\n\n**Use Cases for the Singleton Pattern**\n\n- Should be used when a class must have a single instance available, and it must be accessible to clients from a well-known access point.\n\n- When the sole instance should be extensible by subclassing. and clients should be able to use an extended instance without modifying their code.\n\n**Examples**\n\n- Managing a database connection pool.\n\n- Caching frequently accessed data (Single instance to evict the cache easily).\n\n- Managing application configuration settings.\n\nViolated the single responsibility principle as the object creating and the lifetime of the object is maintained by the class.\n\n```csharp\n// Program.cs\n\nusing Singleton;\n\nConsole.Title = \"Singleton\";\n\n// call the property getter twice\nvar instance1 = Logger.Instance;\nvar instance2 = Logger.Instance;\n\nif (instance1 == instance2)\n{\n    Console.WriteLine(\"Instances are the same.\");\n}\n\ninstance1.Log($\"Message from {nameof(instance1)}\");\n// or\ninstance2.Log($\"Message from {nameof(instance2)}\");\n\nConsole.ReadLine();\n```\n\n```csharp\n// Implementation.cs\n// without handling the multithreading\n\nnamespace Singleton\n{\n    // Singleton\n    public class Logger\n    {\n        private static Logger? _instance = null;\n        // Instance\n        public static Logger Instance\n        {\n            get\n            {\n                if (_instance == null)\n                {\n                    _instance = new Logger();\n                }\n                return _instance;\n            }\n        }\n\n        protected Logger() { }\n\n        // SingletonOperation\n        public void Log(string message)\n        {\n            Console.WriteLine($\"Message to log: {message}\");\n        }\n    }\n}\n```\n\n```csharp\n// Implementation.cs\n// with handling the multithreading by lazy loading\n\nnamespace Singleton\n{\n    // Singleton\n    public class Logger\n    {\n        // Lazy\u003cT\u003e for lazy initialization\n        private static readonly Lazy\u003cLogger\u003e _lazyLogger = new(() =\u003e new Logger());\n\n        // Instance\n        public static Logger Instance\n        {\n            get\n            {\n                return _lazyLogger.Value;\n            }\n        }\n\n        protected Logger() { }\n\n        // SingletonOperation\n        public void Log(string message)\n        {\n            Console.WriteLine($\"Message to log: {message}\");\n        }\n    }\n}\n\n```\n\n### Factory Method\n\n### Abstract Factory\n\n## Structural Patterns\n\n### Adapter\n\n\n### Decorator\n\n### Facade\n\n## Behavioral Patterns\n\n### Command\n\n### Observer\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakazad13%2Fcsharp-design-patterns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakazad13%2Fcsharp-design-patterns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakazad13%2Fcsharp-design-patterns/lists"}