{"id":1647,"date":"2023-04-22T16:10:37","date_gmt":"2023-04-22T09:10:37","guid":{"rendered":"https:\/\/csharptutorial.net\/?page_id=1647"},"modified":"2023-05-13T14:48:59","modified_gmt":"2023-05-13T07:48:59","slug":"csharp-composite","status":"publish","type":"page","link":"https:\/\/www.csharptutorial.net\/csharp-design-patterns\/csharp-composite\/","title":{"rendered":"C# Composite Pattern"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn how to use the C# Composite pattern to treat individual objects and compositions of objects uniformly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to the C# composite pattern<\/h2>\n\n\n\n<p>The C# Composite pattern is a structural design pattern that allows you to create a hierarchy of individual objects and collections of objects through a <a href=\"https:\/\/csharptutorial.net\/csharp-tutorial\/csharp-interface\/\">shared interface<\/a>. This enables the client to treat individual objects and the group of objects uniformly.<\/p>\n\n\n\n<p>Since an individual object and a collection of objects share a common <a href=\"https:\/\/csharptutorial.net\/csharp-tutorial\/csharp-interface\/\">interface<\/a>, the client doesn&#8217;t need to know where it is managing a single object or a collection object. <\/p>\n\n\n\n<p>Instead, the client can make use of polymorphism without having to apply unnecessary <a href=\"https:\/\/csharptutorial.net\/csharp-tutorial\/csharp-if-else\/\">condition statements<\/a> that check whether the object is an individual object or a collection of objects.<\/p>\n\n\n\n<p>To illustrate this composite pattern, imagine you have to manage a bill of materials (BOM) that contains a list of materials for making a part of a product (assembly) or the whole product.<\/p>\n\n\n\n<p>In some cases, you need to perform the same operation on a component whether it is a single component or an assembly that consists of individual components. <\/p>\n\n\n\n<p>For example, you should be able to get the cost of a component without knowing whether it is a component or an assembly.<\/p>\n\n\n\n<p>The following UML diagram illustrates the composite pattern:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/csharptutorial.net\/wp-content\/uploads\/2023\/04\/csharp-composite-pattern.svg\" alt=\"C# composite pattern\" class=\"wp-image-1649\"\/><\/figure>\n<\/div>\n\n\n<p>In this diagram:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>IComponent<\/code>: This is a shared interface that specifies the operation each component needs to implement.<\/li>\n\n\n\n<li><code>Leaf<\/code>: This is an individual component.<\/li>\n\n\n\n<li><code>Composite<\/code>: This is a collection of components. It can include both leaves and other composites.<\/li>\n\n\n\n<li><code>Client<\/code>: This class has access to different components via the shared interface <code>IComponent<\/code>, taking advantage of polymorphism.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">C# Composite pattern example<\/h2>\n\n\n\n<p>The following C# program demonstrates the composite pattern:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"C#\" data-shcb-language-slug=\"cs\"><span><code class=\"hljs language-cs\"><span class=\"hljs-comment\">\/\/ Shared interface<\/span>\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">interface<\/span> <span class=\"hljs-title\">IComponent<\/span>\n{\n    <span class=\"hljs-keyword\">string<\/span> Name { <span class=\"hljs-keyword\">get<\/span>; <span class=\"hljs-keyword\">set<\/span>; }\n    <span class=\"hljs-keyword\">int<\/span> Quantity { <span class=\"hljs-keyword\">get<\/span>; <span class=\"hljs-keyword\">set<\/span>; }\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">double<\/span> <span class=\"hljs-title\">GetCost<\/span>(<span class=\"hljs-params\"><\/span>)<\/span>;\n}\n\n<span class=\"hljs-comment\">\/\/ Leaf component<\/span>\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Part<\/span> : <span class=\"hljs-title\">IComponent<\/span>\n{\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">string<\/span> Name { <span class=\"hljs-keyword\">get<\/span>; <span class=\"hljs-keyword\">set<\/span>; }\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">int<\/span> Quantity { <span class=\"hljs-keyword\">get<\/span>; <span class=\"hljs-keyword\">set<\/span>; }\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">double<\/span> Cost { <span class=\"hljs-keyword\">get<\/span>; <span class=\"hljs-keyword\">set<\/span>; }\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-title\">Part<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">string<\/span> name, <span class=\"hljs-keyword\">int<\/span> quantity, <span class=\"hljs-keyword\">double<\/span> cost<\/span>)<\/span>\n    {\n        Name = name;\n        Quantity = quantity;\n        Cost = cost;\n    }\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">double<\/span> <span class=\"hljs-title\">GetCost<\/span>(<span class=\"hljs-params\"><\/span>)<\/span> =&gt; Cost * Quantity;\n}\n\n<span class=\"hljs-comment\">\/\/ Composite component<\/span>\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Assembly<\/span> : <span class=\"hljs-title\">IComponent<\/span>\n{\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">string<\/span> Name {  <span class=\"hljs-keyword\">get<\/span>; <span class=\"hljs-keyword\">set<\/span>; }\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">int<\/span> Quantity { <span class=\"hljs-keyword\">get<\/span>; <span class=\"hljs-keyword\">set<\/span>; }\n\n    <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-keyword\">readonly<\/span> List&lt;IComponent&gt; _components = <span class=\"hljs-keyword\">new<\/span>();\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-title\">Assembly<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">string<\/span> name, <span class=\"hljs-keyword\">int<\/span> quantity, IEnumerable&lt;IComponent&gt; components<\/span>)<\/span>\n    {\n        Name = name;\n        Quantity = quantity;\n        _components.AddRange(components);\n    }\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">double<\/span> <span class=\"hljs-title\">GetCost<\/span>(<span class=\"hljs-params\"><\/span>)<\/span> =&gt; _components.Sum(component =&gt; component.GetCost());\n}\n\n<span class=\"hljs-comment\">\/\/ Client<\/span>\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Program<\/span>\n{\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">Main<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">string<\/span>&#91;] args<\/span>)<\/span>\n    {\n\n        <span class=\"hljs-comment\">\/\/ parts<\/span>\n        <span class=\"hljs-keyword\">var<\/span> engine = <span class=\"hljs-keyword\">new<\/span> Part(<span class=\"hljs-string\">\"Engine\"<\/span>, <span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">5000.0<\/span>);\n        <span class=\"hljs-keyword\">var<\/span> tires = <span class=\"hljs-keyword\">new<\/span> Part(<span class=\"hljs-string\">\"Tires\"<\/span>, <span class=\"hljs-number\">4<\/span>, <span class=\"hljs-number\">1000.0<\/span>);\n\n        <span class=\"hljs-comment\">\/\/ assembly<\/span>\n        <span class=\"hljs-keyword\">var<\/span> body = <span class=\"hljs-keyword\">new<\/span> Assembly(\n            <span class=\"hljs-string\">\"Body\"<\/span>, \n            <span class=\"hljs-number\">1<\/span>, \n            <span class=\"hljs-keyword\">new<\/span> List&lt;IComponent&gt; {\n                <span class=\"hljs-keyword\">new<\/span> Part(<span class=\"hljs-string\">\"Frame\"<\/span>, <span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">2000.0<\/span>),\n                <span class=\"hljs-keyword\">new<\/span> Part(<span class=\"hljs-string\">\"Doors\"<\/span>, <span class=\"hljs-number\">4<\/span>, <span class=\"hljs-number\">1000.0<\/span>),\n                <span class=\"hljs-keyword\">new<\/span> Part(<span class=\"hljs-string\">\"Windows\"<\/span>, <span class=\"hljs-number\">6<\/span>, <span class=\"hljs-number\">500.0<\/span>)\n            }\n        );\n\n\n        <span class=\"hljs-comment\">\/\/ car<\/span>\n        <span class=\"hljs-keyword\">var<\/span> car = <span class=\"hljs-keyword\">new<\/span> Assembly(\n            <span class=\"hljs-string\">\"Car\"<\/span>, \n            <span class=\"hljs-number\">1<\/span>, \n            <span class=\"hljs-keyword\">new<\/span> List&lt;IComponent&gt; {\n                engine,\n                tires,\n                body\n        });\n\n        <span class=\"hljs-comment\">\/\/ Calculate the cost of the car<\/span>\n        <span class=\"hljs-keyword\">var<\/span> carCost = car.GetCost();\n\n        Console.WriteLine(<span class=\"hljs-string\">$\"The cost of the car is: <span class=\"hljs-subst\">{carCost:C}<\/span>\"<\/span>);\n    }\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">C#<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">cs<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"C#\" data-shcb-language-slug=\"cs\"><span><code class=\"hljs language-cs\">The cost of the car <span class=\"hljs-keyword\">is<\/span>: $<span class=\"hljs-number\">18<\/span>,<span class=\"hljs-number\">000.00<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">C#<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">cs<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>How it works.<\/p>\n\n\n\n<p>First, define a shared interface <code><code>IComponent<\/code><\/code> that both component and assembly need to implement. The <code><code>IComponent<\/code><\/code> interface has the <code>Name<\/code> and <code>Quantity<\/code> properties as well as the <code>GetCost()<\/code> method:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"C#\" data-shcb-language-slug=\"cs\"><span><code class=\"hljs language-cs\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">interface<\/span> <span class=\"hljs-title\">IComponent<\/span>\n{\n    <span class=\"hljs-keyword\">string<\/span> Name { <span class=\"hljs-keyword\">get<\/span>; <span class=\"hljs-keyword\">set<\/span>; }\n    <span class=\"hljs-keyword\">int<\/span> Quantity { <span class=\"hljs-keyword\">get<\/span>; <span class=\"hljs-keyword\">set<\/span>;}\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">double<\/span> <span class=\"hljs-title\">GetCost<\/span>(<span class=\"hljs-params\"><\/span>)<\/span>;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">C#<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">cs<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Second, define the <code>Part<\/code> class that serves as a leaf. The <code>Part<\/code> class implements the <code>IComponent<\/code> interface:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"C#\" data-shcb-language-slug=\"cs\"><span><code class=\"hljs language-cs\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Part<\/span> : <span class=\"hljs-title\">IComponent<\/span>\n{\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">string<\/span> Name { <span class=\"hljs-keyword\">get<\/span>; <span class=\"hljs-keyword\">set<\/span>; }\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">int<\/span> Quantity {  <span class=\"hljs-keyword\">get<\/span>; <span class=\"hljs-keyword\">set<\/span>; }\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">double<\/span> Cost { <span class=\"hljs-keyword\">get<\/span>; <span class=\"hljs-keyword\">set<\/span>; }\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-title\">Part<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">string<\/span> name, <span class=\"hljs-keyword\">int<\/span> quantity, <span class=\"hljs-keyword\">double<\/span> cost<\/span>)<\/span>\n    {\n        Name = name;\n        Quantity = quantity;\n        Cost = cost;\n    }\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">double<\/span> <span class=\"hljs-title\">GetCost<\/span>(<span class=\"hljs-params\"><\/span>)<\/span> =&gt; Cost * Quantity;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">C#<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">cs<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In the Part class, the <code>GetCost()<\/code> calculates the cost by multiplying the cost of each component by the quantity.<\/p>\n\n\n\n<p>Third, define the <code>Assembly<\/code> class that serves as the composite. The <code>Assembly<\/code> class implements the <code><code><code>IComponent<\/code><\/code><\/code> interface and has a field with the type of <code>IEnumerable<\/code>&lt;<code><code><code>IComponent<\/code><\/code><\/code>&gt; that represents a list of <code><code><code>IComponent<\/code><\/code><\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"C#\" data-shcb-language-slug=\"cs\"><span><code class=\"hljs language-cs\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Assembly<\/span> : <span class=\"hljs-title\">IComponent<\/span>\n{\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">string<\/span> Name {  <span class=\"hljs-keyword\">get<\/span>; <span class=\"hljs-keyword\">set<\/span>; }\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">int<\/span> Quantity { <span class=\"hljs-keyword\">get<\/span>; <span class=\"hljs-keyword\">set<\/span>; }\n\n    <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-keyword\">readonly<\/span> List&lt;IComponent&gt; _components = <span class=\"hljs-keyword\">new<\/span>();\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-title\">Assembly<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">string<\/span> name, <span class=\"hljs-keyword\">int<\/span> quantity, IEnumerable&lt;IComponent&gt; components<\/span>)<\/span>\n    {\n        Name = name;\n        Quantity = quantity;\n        _components.AddRange(components);\n    }\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">double<\/span> <span class=\"hljs-title\">GetCost<\/span>(<span class=\"hljs-params\"><\/span>)<\/span> =&gt; _components.Sum(component =&gt; component.GetCost());\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">C#<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">cs<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>GetCost()<\/code> method calculates the total cost by using the <code><a href=\"https:\/\/csharptutorial.net\/csharp-linq\/linq-sum\/\">Sum<\/a><\/code> extension method by adding up the costs of all the components in the <code>_component<\/code> list.<\/p>\n\n\n\n<p>Finally, define the <code>Program<\/code> class that uses the <code>Part<\/code> and <code>Assembly<\/code> classes to construct a Car product and call the <code>GetCost()<\/code> of the car object to get the total cost of the car:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"C#\" data-shcb-language-slug=\"cs\"><span><code class=\"hljs language-cs\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Program<\/span>\n{\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">Main<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">string<\/span>&#91;] args<\/span>)<\/span>\n    {\n\n        <span class=\"hljs-comment\">\/\/ parts<\/span>\n        <span class=\"hljs-keyword\">var<\/span> engine = <span class=\"hljs-keyword\">new<\/span> Part(<span class=\"hljs-string\">\"Engine\"<\/span>, <span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">5000.0<\/span>);\n        <span class=\"hljs-keyword\">var<\/span> tires = <span class=\"hljs-keyword\">new<\/span> Part(<span class=\"hljs-string\">\"Tires\"<\/span>, <span class=\"hljs-number\">4<\/span>, <span class=\"hljs-number\">1000.0<\/span>);\n\n        <span class=\"hljs-comment\">\/\/ assembly<\/span>\n        <span class=\"hljs-keyword\">var<\/span> body = <span class=\"hljs-keyword\">new<\/span> Assembly(<span class=\"hljs-string\">\"Body\"<\/span>, <span class=\"hljs-number\">1<\/span>, <span class=\"hljs-keyword\">new<\/span> List&lt;IComponent&gt; {\n            <span class=\"hljs-keyword\">new<\/span> Part(<span class=\"hljs-string\">\"Frame\"<\/span>, <span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">2000.0<\/span>),\n            <span class=\"hljs-keyword\">new<\/span> Part(<span class=\"hljs-string\">\"Doors\"<\/span>, <span class=\"hljs-number\">4<\/span>, <span class=\"hljs-number\">1000.0<\/span>),\n            <span class=\"hljs-keyword\">new<\/span> Part(<span class=\"hljs-string\">\"Windows\"<\/span>, <span class=\"hljs-number\">6<\/span>, <span class=\"hljs-number\">500.0<\/span>)\n        });\n\n        <span class=\"hljs-comment\">\/\/ car<\/span>\n        <span class=\"hljs-keyword\">var<\/span> car = <span class=\"hljs-keyword\">new<\/span> Assembly(<span class=\"hljs-string\">\"Car\"<\/span>, <span class=\"hljs-number\">1<\/span>, <span class=\"hljs-keyword\">new<\/span> List&lt;IComponent&gt;{\n            engine,\n            tires,\n            body\n        });\n\n        <span class=\"hljs-comment\">\/\/ Calculate the cost of the car<\/span>\n        <span class=\"hljs-keyword\">var<\/span> carCost = car.GetCost();\n\n        Console.WriteLine(<span class=\"hljs-string\">$\"The cost of the car is: <span class=\"hljs-subst\">{carCost:C}<\/span>\"<\/span>);\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">C#<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">cs<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the Composite pattern to treat individual objects and compositions of objects uniformly.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"1647\"\n\t\t\t\tdata-post-url=\"https:\/\/www.csharptutorial.net\/csharp-design-patterns\/csharp-composite\/\"\n\t\t\t\tdata-post-title=\"C# Composite Pattern\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"1647\"\n\t\t\t\tdata-post-url=\"https:\/\/www.csharptutorial.net\/csharp-design-patterns\/csharp-composite\/\"\n\t\t\t\tdata-post-title=\"C# Composite Pattern\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you&#8217;ll learn how to use the C# Composite pattern to treat individual objects and compositions of objects uniformly.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1441,"menu_order":23,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1647","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/pages\/1647","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/comments?post=1647"}],"version-history":[{"count":4,"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/pages\/1647\/revisions"}],"predecessor-version":[{"id":1817,"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/pages\/1647\/revisions\/1817"}],"up":[{"embeddable":true,"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/pages\/1441"}],"wp:attachment":[{"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/media?parent=1647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}