{"id":47667,"date":"2019-03-23T08:18:19","date_gmt":"2019-03-23T07:18:19","guid":{"rendered":"https:\/\/code-maze.com\/?page_id=47667"},"modified":"2024-08-28T08:30:23","modified_gmt":"2024-08-28T06:30:23","slug":"design-patterns-csharp","status":"publish","type":"page","link":"https:\/\/code-maze.com\/design-patterns-csharp\/","title":{"rendered":"Design Patterns in C#"},"content":{"rendered":"<p>There are a lot of different design patterns in C#. You can find a pattern for every situation. Should we use them whenever we can?<\/p>\n<p>Of course not!<\/p>\n<p>While design patterns generally should improve our code in theory, in practice it&#8217;s not uncommon to find a lot of misused and wrongly implemented design patterns.<\/p>\n<p>The most common mistakes happen when people learn design patterns and try to implement them everywhere without the real need for them. The most important part of applying patterns to your codebase is knowing when and where to apply each pattern.<\/p>\n<p>You can easily find the implementation anywhere on the internet. Even multiple implementations of the same pattern. But if you implement them just for the sake of the pattern, you will probably do more damage to your project.<\/p>\n<p>So we&#8217;ve decided to go over the most commonly used patterns in C# and explain where you can apply them and give some nice examples to give you some context.<\/p>\n<p>We can split design patterns in C# into multiple categories.<\/p>\n<h2>Creational Design Patterns<\/h2>\n<ul>\n<li><a href=\"https:\/\/code-maze.com\/builder-design-pattern\/\" target=\"_blank\" rel=\"noopener noreferrer\">Builder<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/fluent-builder-recursive-generics\/\" target=\"_blank\" rel=\"noopener noreferrer\">Fluent Builder Interface With Recursive Generics<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/faceted-builder\/\" target=\"_blank\" rel=\"noopener noreferrer\">Faceted Builder<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/factory-method\/\" target=\"_blank\" rel=\"noopener noreferrer\">Factory Method<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/singleton\/\" target=\"_blank\" rel=\"noopener noreferrer\">Singleton<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-abstract-factory-design-pattern\/\" target=\"_blank\" rel=\"noopener\">Abstract Factory<\/a><\/li>\n<\/ul>\n<h2>Structural Design Patterns<\/h2>\n<ul>\n<li><a href=\"https:\/\/code-maze.com\/adapter\/\" target=\"_blank\" rel=\"noopener noreferrer\">Adapter<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/composite\/\" target=\"_blank\" rel=\"noopener noreferrer\">Composite<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/decorator-design-pattern\/\" target=\"_blank\" rel=\"noopener noreferrer\">Decorator<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/facade\/\" target=\"_blank\" rel=\"noopener noreferrer\">Facade<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-proxy-design-pattern\/\" target=\"_blank\" rel=\"noopener\">Proxy<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-bridge-design-pattern\/\" target=\"_blank\" rel=\"noopener\">Bridge<\/a><\/li>\n<\/ul>\n<h2>Behavioral Design Patterns<\/h2>\n<ul>\n<li><a href=\"https:\/\/code-maze.com\/command\/\" target=\"_blank\" rel=\"noopener noreferrer\">Command<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/strategy\/\" target=\"_blank\" rel=\"noopener noreferrer\">Strategy<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-visitor-design-pattern\/\" target=\"_blank\" rel=\"noopener\">Visitor<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-observer-design-pattern\/\" target=\"_blank\" rel=\"noopener\">Observer<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-template-method-design-pattern\/\" target=\"_blank\" rel=\"noopener\">Template<\/a><\/li>\n<\/ul>\n<h2>Other Popular Design Patterns<\/h2>\n<ul>\n<li><a class=\"row-title\" href=\"https:\/\/code-maze.com\/csharp-unit-of-work-pattern\/\" target=\"_blank\" rel=\"noopener\" aria-label=\"\u201cUnderstanding the Unit of Work Pattern in C#\u201d (Edit)\">Unit of Work<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-saga-pattern-with-nservicebus\/\" target=\"_blank\" rel=\"noopener\">Saga Pattern<\/a><\/li>\n<\/ul>\n<p>Of course, these are not all the patterns out there, but we&#8217;ll continue to add more!<\/p>\n<p>What are your favorite design patterns in C#? Which one do you use the most?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are a lot of different design patterns in C#. You can find a pattern for every situation. Should we use them whenever we can? Of course not! While design patterns generally should improve our code in theory, in practice it&#8217;s not uncommon to find a lot of misused and wrongly implemented design patterns. The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"class_list":["post-47667","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Design Patterns in C# - Code Maze<\/title>\n<meta name=\"description\" content=\"Collection of Design Patterns in C#. You will find different desing patterns explained using detailed examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/design-patterns-csharp\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Design Patterns in C# - Code Maze\" \/>\n<meta property=\"og:description\" content=\"Collection of Design Patterns in C#. You will find different desing patterns explained using detailed examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/design-patterns-csharp\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-28T06:30:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/05\/Code-Maze-Banner-Final-White-BG-wo-Glow.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/design-patterns-csharp\/\",\"url\":\"https:\/\/code-maze.com\/design-patterns-csharp\/\",\"name\":\"Design Patterns in C# - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"datePublished\":\"2019-03-23T07:18:19+00:00\",\"dateModified\":\"2024-08-28T06:30:23+00:00\",\"description\":\"Collection of Design Patterns in C#. You will find different desing patterns explained using detailed examples.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/design-patterns-csharp\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/design-patterns-csharp\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/design-patterns-csharp\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Design Patterns in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Design Patterns in C# - Code Maze","description":"Collection of Design Patterns in C#. You will find different desing patterns explained using detailed examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/design-patterns-csharp\/","og_locale":"en_US","og_type":"article","og_title":"Design Patterns in C# - Code Maze","og_description":"Collection of Design Patterns in C#. You will find different desing patterns explained using detailed examples.","og_url":"https:\/\/code-maze.com\/design-patterns-csharp\/","og_site_name":"Code Maze","article_modified_time":"2024-08-28T06:30:23+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/05\/Code-Maze-Banner-Final-White-BG-wo-Glow.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@CodeMazeBlog","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/code-maze.com\/design-patterns-csharp\/","url":"https:\/\/code-maze.com\/design-patterns-csharp\/","name":"Design Patterns in C# - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"datePublished":"2019-03-23T07:18:19+00:00","dateModified":"2024-08-28T06:30:23+00:00","description":"Collection of Design Patterns in C#. You will find different desing patterns explained using detailed examples.","breadcrumb":{"@id":"https:\/\/code-maze.com\/design-patterns-csharp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/design-patterns-csharp\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/design-patterns-csharp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"Design Patterns in C#"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/pages\/47667","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=47667"}],"version-history":[{"count":15,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/pages\/47667\/revisions"}],"predecessor-version":[{"id":123368,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/pages\/47667\/revisions\/123368"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=47667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}