{"id":25404178,"url":"https://github.com/pravinchandankhede/designpatterns","last_synced_at":"2025-04-12T17:53:08.195Z","repository":{"id":263540205,"uuid":"890723171","full_name":"pravinchandankhede/designpatterns","owner":"pravinchandankhede","description":"This repo contains the implementation of various design patterns implementation using C#.","archived":false,"fork":false,"pushed_at":"2025-03-20T08:40:49.000Z","size":44,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-20T09:37:10.653Z","etag":null,"topics":["architecture","csharp","design-patterns","foundational-patterns","software-architecture"],"latest_commit_sha":null,"homepage":"https://pravinchandankhede.github.io/","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/pravinchandankhede.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-11-19T04:13:29.000Z","updated_at":"2025-03-20T08:40:53.000Z","dependencies_parsed_at":"2025-03-20T09:28:49.422Z","dependency_job_id":"019cb2f0-c3d4-4bcc-915b-4adb40f19780","html_url":"https://github.com/pravinchandankhede/designpatterns","commit_stats":null,"previous_names":["pravinchandankhede/designpatterns"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pravinchandankhede%2Fdesignpatterns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pravinchandankhede%2Fdesignpatterns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pravinchandankhede%2Fdesignpatterns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pravinchandankhede%2Fdesignpatterns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pravinchandankhede","download_url":"https://codeload.github.com/pravinchandankhede/designpatterns/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248610408,"owners_count":21132920,"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":["architecture","csharp","design-patterns","foundational-patterns","software-architecture"],"created_at":"2025-02-16T03:40:07.592Z","updated_at":"2025-04-12T17:53:08.175Z","avatar_url":"https://github.com/pravinchandankhede.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Unit Tests](https://github.com/pravinchandankhede/designpatterns/actions/workflows/dotnet.yml/badge.svg)](https://github.com/pravinchandankhede/designpatterns/actions/workflows/dotnet.yml)\n\n# Design Patterns\n\nThis repo contains the implementation of various design patterns implementation using C#. It also demonstrates posibilities to implement same pattern in different ways\n\nBroadly there are 3 types of design patterns prevelant in use. these are based on famous [GOF](https://en.wikipedia.org/wiki/Design_Patterns)\n\n## Creational Patterns\nThese patterns deal with creation of object instances. These are of different types depending on what you intend to do with them. \n\n### [Singleton](https://en.wikipedia.org/wiki/Singleton_pattern)\nThis pattern ensure that only one instance of a class is created at any point of time. The sample code demonstrate different way of implementing singleton pattern.\nRefer the entire implementation [here](https://github.com/pravinchandankhede/designpatterns/tree/main/src/creational/Singleton).\n\n1. [Basic](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/Singleton/Basic.cs) This class implements a very basic version of singleton using private constructor and factory method to instanciate the instance.\n2. [Eager](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/Singleton/EagerSingleton.cs) This class implements the eager initialization pattern fro creating singleton objects.\n3. [Lazy](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/Singleton/LazySingleton.cs) This class shows how to utilize the [Lazy\u003cT\u003e](https://learn.microsoft.com/en-us/dotnet/api/system.lazy-1?view=net-9.0) feature of C# to implement singleton pattern.\n4. [Thread Safe](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/Singleton/ThreadSafeSingleton.cs) This class implements a thread safe version of singleton using the static constructor method.\n5. [Thread Lock](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/Singleton/ThreadLockSingleton.cs) This class shows how to create a singleton class by using a lock to synchronize the creation of instance between multiple threads.\n\n### [Factory](https://en.wikipedia.org/wiki/Factory_method_pattern)\nThis pattern is used to create objects without exposing the instantiation logic to the client. The sample code demonstrate different way of implementing factory pattern.\nRefer the entire implementation [here](https://github.com/pravinchandankhede/designpatterns/tree/main/src/creational/FactoryMethod).\n\n#### Traditonal Factory\nThis demonstrates the class [AccountFactory](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/FactoryMethod/AccountFactory/AccountFactory.cs) which creates instance of [SavingAccount](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/FactoryMethod/Account/SavingAccount.cs) or [CurrentAccount](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/FactoryMethod/Account/CurrentAccount.cs) and returns a [IAccount](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/FactoryMethod/Account/IAccount.cs) object. This uses the classic [new()](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/new-operator) operator to create instances. The caller can work with both the instances in exactly same way, abstracting thier internal details and implementation details.\n\n#### Factory using Dependency Injection\nThe class [AccountFactoryServiceProvider](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/FactoryMethod/AccountFactory/AccountFactoryServiceProvider.cs) demonstrates how to use [IServiceCollection](https://learn.microsoft.com/en-us/dotnet/api/system.iserviceprovider?view=net-9.0) to create instances of [SavingAccount](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/FactoryMethod/Account/SavingAccount.cs) or [CurrentAccount](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/FactoryMethod/Account/CurrentAccount.cs) and return [IAccount](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/FactoryMethod/Account/IAccount.cs) object. This uses the [IServiceCollection](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection?view=dotnet-plat-ext-5.0) to create instances. The caller can work with both the instances in exactly same way, abstracting thier internal details and implementation details.\n\n#### Factory using Reflection\nThe class [AccountFactoryReflection](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/FactoryMethod/AccountFactory/AccountFactoryReflection.cs) demonstrates how to use [Activator](https://learn.microsoft.com/en-us/dotnet/api/system.activator?view=net-9.0) to create instances of [SavingAccount](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/FactoryMethod/Account/SavingAccount.cs) or [CurrentAccount](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/FactoryMethod/Account/CurrentAccount.cs) and return [IAccount](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/FactoryMethod/Account/IAccount.cs) object. The caller can work with both the instances in exactly same way, abstracting thier internal details and implementation details.\n\nIt also shows how to leverage a base class [AccountBase](https://github.com/pravinchandankhede/designpatterns/blob/main/src/creational/FactoryMethod/AccountFactory/AccountBase.cs) to provide common fields and functionality across all derived class. This enables us to create a common abstraction among all derived classes and still make use of Factory to create instance thereby ensuring common pattern id followed by each client.\n\n## Structural Patterns\nThese patterns deals with the structure of code and classes. It highlights how different classes interact to form a larger system of classes.\n\n## Behavioral Patterns\nThese patterns deals with the interaction and behavioral responsibilities of classes involved in the overall design.\n\n## Installation\nYou can fork the repository at your local machine and run the code using Visual Studio or any other IDE of your choice.\n\n## Contributing\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpravinchandankhede%2Fdesignpatterns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpravinchandankhede%2Fdesignpatterns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpravinchandankhede%2Fdesignpatterns/lists"}