{"id":47505,"date":"2019-03-04T08:01:49","date_gmt":"2019-03-04T07:01:49","guid":{"rendered":"https:\/\/code-maze.com\/?p=47505"},"modified":"2024-08-06T12:28:06","modified_gmt":"2024-08-06T10:28:06","slug":"adapter","status":"publish","type":"post","link":"https:\/\/code-maze.com\/adapter\/","title":{"rendered":"C# Design Patterns &#8211; Adapter"},"content":{"rendered":"<p>The Adapter design pattern is a structural pattern that allows incompatible interfaces to work together. By doing so, we allow objects from different interfaces to exchange data.<\/p>\n<p>In this article, we are going to learn how to implement the Adapter pattern into our project and when should we use it.<\/p>\n<ul id=\"series_parts\" style=\"display: none;\">\n<li><a href=\"https:\/\/code-maze.com\/builder-design-pattern\/\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"font-size: 12pt;\">Builder Design Pattern and Fluent Builder<\/span><\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/fluent-builder-recursive-generics\/\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"font-size: 12pt;\">Fluent Builder Interface With Recursive Generics\u00a0<\/span><\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/faceted-builder\/\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"font-size: 12pt;\">Faceted Builder\u00a0<\/span><\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/factory-method\/\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"font-size: 12pt;\">Factory Method\u00a0<\/span><\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/singleton\/\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"font-size: 12pt;\">Singleton\u00a0<\/span><\/a><\/li>\n<li><span style=\"font-size: 12pt;\">Adapter (Current article)<\/span><\/li>\n<li><span style=\"font-size: 12pt;\"><a href=\"https:\/\/code-maze.com\/composite\/\" target=\"_blank\" rel=\"noopener noreferrer\">Composite<\/a><\/span><\/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\/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<\/ul>\n<div style=\"padding: 20px; border-left: 5px color:#dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for the video, visit our <a href=\"https:\/\/www.patreon.com\/posts\/source-code-in-109495517?src=AdapterDesignPattern\" target=\"_blank\" rel=\"nofollow noopener\">Patreon page<\/a> (YouTube Patron tier).<\/div>\n<p>For the main page of this series check out <a href=\"https:\/\/code-maze.com\/design-patterns-csharp\/\" target=\"_blank\" rel=\"noopener noreferrer\">C# Design Patterns.<\/a><\/p>\n<hr \/>\r\n<p style=\"text-align: center;\"><strong>VIDEO<\/strong>: Adapter Design Pattern in C#.<\/p>\r\n<p style=\"text-align: center;\"><iframe width=\"560\" height=\"315\" src=https:\/\/www.youtube.com\/embed\/cmc3H5j0nDo?si=LgAKzUpAeF8mEADj frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\r\n<hr \/>\n<h2 id=\"initialproject\">Initial Project<\/h2>\n<p>Let\u2019s imagine that we have functionality in which we convert the list of car manufacturers into JSON format and write it to the screen. But instead of a list, we have been provided with an API that provides us with all the manufacturers in the XML format.<\/p>\n<p>Let\u2019s say we can\u2019t modify the existing API functionality (because of the technical restrictions such as being imported into our project from another solution that we mustn\u2019t modify or as a NuGet package) so we have to find a way around it.<\/p>\n<p>And the proper way to do it is to implement the Adapter pattern to solve this problem.<\/p>\n<p>Let\u2019s start with the creation of the <code>Manufacturer<\/code> model and a simple object to XML converter example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public class Manufacturer\r\n{\r\n    public string Name { get; set; }\r\n    public string City { get; set; }\r\n    public int Year { get; set; }\r\n}\r\n<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static class ManufacturerDataProvider\r\n{\r\n    public List&lt;Manufacturer&gt; GetData() =&gt;\r\n       new List&lt;Manufacturer&gt;\r\n       {\r\n            new Manufacturer { City = \"Italy\", Name = \"Alfa Romeo\", Year = 2016 },\r\n            new Manufacturer { City = \"UK\", Name = \"Aston Martin\", Year = 2018 },\r\n            new Manufacturer { City = \"USA\", Name = \"Dodge\", Year = 2017 },\r\n            new Manufacturer { City = \"Japan\", Name = \"Subaru\", Year = 2016 },\r\n            new Manufacturer { City = \"Germany\", Name = \"BMW\", Year = 2015 }\r\n       };\r\n}\r\n<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public class XmlConverter\r\n{\r\n    public XDocument GetXML()\r\n    {\r\n        var xDocument = new XDocument();\r\n        var xElement = new XElement(\"Manufacturers\");\r\n        var xAttributes = ManufacturerDataProvider.GetData()\r\n            .Select(m =&gt; new XElement(\"Manufacturer\", \r\n                                new XAttribute(\"City\", m.City),\r\n                                new XAttribute(\"Name\", m.Name),\r\n                                new XAttribute(\"Year\", m.Year)));\r\n\r\n        xElement.Add(xAttributes);\r\n        xDocument.Add(xElement);\r\n\r\n        Console.WriteLine(xDocument);\r\n\r\n        return xDocument;\r\n    }\r\n}\r\n<\/pre>\n<p>As we can see, this is a pretty straightforward code. We are collecting manufacturer data, creating a root Manufacturers element and all the Manufacturer sub-elements with its attributes.<\/p>\n<p>After that, we are printing results to the console window to show how the final XML looks like.<\/p>\n<p>This is how the <code>xDocument<\/code> should look like:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2019\/03\/01-Xml-document.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-47507\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2019\/03\/01-Xml-document.png\" alt=\"Xml Conver - Adapter Design Pattern\" width=\"563\" height=\"224\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2019\/03\/01-Xml-document.png 563w, https:\/\/code-maze.com\/wp-content\/uploads\/2019\/03\/01-Xml-document-300x119.png 300w\" sizes=\"auto, (max-width: 563px) 100vw, 563px\" \/><\/a><\/p>\n<p>Now let\u2019s implement a <code>JsonConverter<\/code> class:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public class JsonConverter\r\n{\r\n    private IEnumerable&lt;Manufacturer&gt; _manufacturers;\r\n\r\n    public JsonConverter(IEnumerable&lt;Manufacturer&gt; manufacturers)\r\n    {\r\n        _manufacturers = manufacturers;\r\n    }\r\n\r\n    public void ConvertToJson()\r\n    {\r\n        var jsonManufacturers = JsonConvert.SerializeObject(_manufacturers, Formatting.Indented);\r\n\r\n        Console.WriteLine(\"\\nPrinting JSON list\\n\");\r\n        Console.WriteLine(jsonManufacturers);\r\n    }\r\n} \r\n<\/pre>\n<p>This code is even simpler because we only serialize our manufacturer\u00a0list into a JSON format.<\/p>\n<p>Of course, for the serialization to work we need to install the <code>Newtonsoft.Json<\/code> library, so don\u2019t forget to do that.<\/p>\n<p>Excellent, we have our JSON functionality and the provided XML interface. But now, we need to solve a real problem. How to combine those two interfaces to accomplish our task, which is converting manufacturers from XML to JSON format.<\/p>\n<h2 id=\"adapterimplementation\">Adapter Implementation<\/h2>\n<p>As we can see, there is no way to pass an <code>xDocument<\/code> to the <code>JsonConverter<\/code> class and there shouldn\u2019t be one, so we need to create the adapter class which will make these two interfaces work together.<\/p>\n<p>To do this, we are going to start with the <code>IXmlToJson<\/code> interface to define the behavior of our adapter class:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public interface IXmlToJson\r\n{\r\n    void ConvertXmlToJson();\r\n}\r\n<\/pre>\n<p>Then, let\u2019s continue with the <code>XmlToJsonAdapter<\/code> class which is going to implement the <code>IXmlToJson<\/code> interface:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public class XmlToJsonAdapter : IXmlToJson\r\n{\r\n    private readonly XmlConverter _xmlConverter;\r\n\r\n    public XmlToJsonAdapter(XmlConverter xmlConverter)\r\n    {\r\n        _xmlConverter = xmlConverter;\r\n    }\r\n\r\n    public void ConvertXmlToJson()\r\n    {\r\n        var manufacturers = _xmlConverter.GetXML()\r\n                .Element(\"Manufacturers\")\r\n                .Elements(\"Manufacturer\")\r\n                .Select(m =&gt; new Manufacturer\r\n                             {\r\n                                City = m.Attribute(\"City\").Value,\r\n                                Name = m.Attribute(\"Name\").Value,\r\n                                Year = Convert.ToInt32(m.Attribute(\"Year\").Value)\r\n                             });\r\n\r\n        new JsonConverter(manufacturers)\r\n            .ConvertToJson();\r\n    }\r\n}\r\n<\/pre>\n<p>Excellent. We have created our adapter class which converts the Xml document object into the list of manufacturers and provides that list to the <code>JsonConverter<\/code> class.<\/p>\n<p>So, as you can see, we have enabled collaboration between two completely different interfaces by just introducing an adapter class to our project.<\/p>\n<p>Now, we can make a call to this adapter class from our client class:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">class Program\r\n{\r\n   static void Main(string[] args)\r\n    {\r\n        var xmlConverter = new XmlConverter();\r\n        var adapter = new XmlToJsonAdapter(xmlConverter);\r\n        adapter.ConvertXmlToJson();\r\n    }\r\n}\r\n<\/pre>\n<p>Once we start our application, we are going to see the following result:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2019\/03\/02-Final-result.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-47508\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2019\/03\/02-Final-result.png\" alt=\"Adapter - JSON Convert\" width=\"688\" height=\"672\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2019\/03\/02-Final-result.png 688w, https:\/\/code-maze.com\/wp-content\/uploads\/2019\/03\/02-Final-result-300x293.png 300w, https:\/\/code-maze.com\/wp-content\/uploads\/2019\/03\/02-Final-result-600x586.png 600w\" sizes=\"auto, (max-width: 688px) 100vw, 688px\" \/><\/a><\/p>\n<p>Great job. We have finished our implementation.<\/p>\n<h2 id=\"whentouseadapter\">When to Use Adapter<\/h2>\n<p>We should use the Adapter class whenever we want to work with the existing class but its interface is not compatible with the rest of our code. Basically, the Adapter pattern is a middle-layer which serves as a translator between the code implemented in our project and some third party class or any other class with a different interface.<\/p>\n<p>Furthermore, we should use the Adapter when we want to reuse existing classes from our project but they lack a common functionality. By using the Adapter pattern in this case, we don\u2019t need to extend each class separately and create a redundant code.<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>The Adapter pattern is pretty common in the C# world and it is quite used when we have to adapt some existing classes to a new interface. It can increase a code complexity by adding additional classes (adapters) but it is worth an effort for sure.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Adapter design pattern is a structural pattern that allows incompatible interfaces to work together. By doing so, we allow objects from different interfaces to exchange data. In this article, we are going to learn how to implement the Adapter pattern into our project and when should we use it. Builder Design Pattern and Fluent [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":51901,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12,504],"tags":[494,433],"class_list":["post-47505","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","category-design-pattern","tag-adapter","tag-design-patterns","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C# Design Patterns - Adapter Design Pattern - Code Maze<\/title>\n<meta name=\"description\" content=\"In this article we are going to learn about Adapter design pattern, how to implement it in the project and when shoud we use it.\" \/>\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\/adapter\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C# Design Patterns - Adapter Design Pattern - Code Maze\" \/>\n<meta property=\"og:description\" content=\"In this article we are going to learn about Adapter design pattern, how to implement it in the project and when shoud we use it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/adapter\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-04T07:01:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-06T10:28:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/03\/adapter.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Marinko Spasojevi\u0107\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Marinko Spasojevi\u0107\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/adapter\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/adapter\/\"},\"author\":{\"name\":\"Marinko Spasojevi\u0107\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533\"},\"headline\":\"C# Design Patterns &#8211; Adapter\",\"datePublished\":\"2019-03-04T07:01:49+00:00\",\"dateModified\":\"2024-08-06T10:28:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/adapter\/\"},\"wordCount\":698,\"commentCount\":11,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/adapter\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/03\/adapter.png\",\"keywords\":[\"Adapter\",\"Design Patterns\"],\"articleSection\":[\"C#\",\"Design Pattern\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/adapter\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/adapter\/\",\"url\":\"https:\/\/code-maze.com\/adapter\/\",\"name\":\"C# Design Patterns - Adapter Design Pattern - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/adapter\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/adapter\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/03\/adapter.png\",\"datePublished\":\"2019-03-04T07:01:49+00:00\",\"dateModified\":\"2024-08-06T10:28:06+00:00\",\"description\":\"In this article we are going to learn about Adapter design pattern, how to implement it in the project and when shoud we use it.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/adapter\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/adapter\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/adapter\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/03\/adapter.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/03\/adapter.png\",\"width\":1100,\"height\":620,\"caption\":\"adapter\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/adapter\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C# Design Patterns &#8211; Adapter\"}]},{\"@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\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533\",\"name\":\"Marinko Spasojevi\u0107\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg\",\"caption\":\"Marinko Spasojevi\u0107\"},\"description\":\"Hi, my name is Marinko Spasojevic. Currently, I work as a full-time .NET developer and my passion is web application development. Just getting something to work is not enough for me. To make it just how I like it, it must be readable, reusable, and easy to maintain. Prior to being an author on the CodeMaze blog, I had been working as a professor of Computer Science for several years. So, sharing knowledge while working as a full-time developer comes naturally to me.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/marinko-spasojevic\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/marinko\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C# Design Patterns - Adapter Design Pattern - Code Maze","description":"In this article we are going to learn about Adapter design pattern, how to implement it in the project and when shoud we use it.","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\/adapter\/","og_locale":"en_US","og_type":"article","og_title":"C# Design Patterns - Adapter Design Pattern - Code Maze","og_description":"In this article we are going to learn about Adapter design pattern, how to implement it in the project and when shoud we use it.","og_url":"https:\/\/code-maze.com\/adapter\/","og_site_name":"Code Maze","article_published_time":"2019-03-04T07:01:49+00:00","article_modified_time":"2024-08-06T10:28:06+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/03\/adapter.png","type":"image\/png"}],"author":"Marinko Spasojevi\u0107","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Marinko Spasojevi\u0107","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/adapter\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/adapter\/"},"author":{"name":"Marinko Spasojevi\u0107","@id":"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533"},"headline":"C# Design Patterns &#8211; Adapter","datePublished":"2019-03-04T07:01:49+00:00","dateModified":"2024-08-06T10:28:06+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/adapter\/"},"wordCount":698,"commentCount":11,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/adapter\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/03\/adapter.png","keywords":["Adapter","Design Patterns"],"articleSection":["C#","Design Pattern"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/adapter\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/adapter\/","url":"https:\/\/code-maze.com\/adapter\/","name":"C# Design Patterns - Adapter Design Pattern - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/adapter\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/adapter\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/03\/adapter.png","datePublished":"2019-03-04T07:01:49+00:00","dateModified":"2024-08-06T10:28:06+00:00","description":"In this article we are going to learn about Adapter design pattern, how to implement it in the project and when shoud we use it.","breadcrumb":{"@id":"https:\/\/code-maze.com\/adapter\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/adapter\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/adapter\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/03\/adapter.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/03\/adapter.png","width":1100,"height":620,"caption":"adapter"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/adapter\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"C# Design Patterns &#8211; Adapter"}]},{"@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"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533","name":"Marinko Spasojevi\u0107","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg","caption":"Marinko Spasojevi\u0107"},"description":"Hi, my name is Marinko Spasojevic. Currently, I work as a full-time .NET developer and my passion is web application development. Just getting something to work is not enough for me. To make it just how I like it, it must be readable, reusable, and easy to maintain. Prior to being an author on the CodeMaze blog, I had been working as a professor of Computer Science for several years. So, sharing knowledge while working as a full-time developer comes naturally to me.","sameAs":["https:\/\/www.linkedin.com\/in\/marinko-spasojevic\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/marinko\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/47505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=47505"}],"version-history":[{"count":6,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/47505\/revisions"}],"predecessor-version":[{"id":120914,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/47505\/revisions\/120914"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/51901"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=47505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=47505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=47505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}