<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Azeez Adio</title>
    <description>The latest articles on DEV Community by Azeez Adio (@azeezabp).</description>
    <link>https://dev.to/azeezabp</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F914410%2Ff553d466-4101-4bac-93ec-fbed4b7df49d.png</url>
      <title>DEV Community: Azeez Adio</title>
      <link>https://dev.to/azeezabp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/azeezabp"/>
    <language>en</language>
    <item>
      <title>Decorator Design Pattern in php</title>
      <dc:creator>Azeez Adio</dc:creator>
      <pubDate>Sun, 05 Mar 2023 06:08:39 +0000</pubDate>
      <link>https://dev.to/azeezabp/decorator-design-pattern-a9h</link>
      <guid>https://dev.to/azeezabp/decorator-design-pattern-a9h</guid>
      <description>&lt;p&gt;Decorator design patter is a structural design patter that provide a means of adding new properties to an object.&lt;br&gt;
How?&lt;br&gt;
Let's look at the component of the this pattern&lt;br&gt;
Main components&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;interface (template for the object to be of the same type)&lt;/li&gt;
&lt;li&gt;Class  to Decorate that implements the interface &lt;/li&gt;
&lt;li&gt;class that decorate(decorator) is and abstract  class the implements the interface
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Auxiliary components&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;class that inherit decorator class
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface BuidingConcern{

    function addComponent($what);
    function removerComponent();

}


class House implements BuidingConcern{
    /////////class to decorate

    function addComponent($what){
        return  ' has added '. $what;

    }

     function removerComponent(){

     }


}

abstract class Worker implements BuidingConcern{
//class that decorate
    protected BuidingConcern $house ; ///protect so that childeren class can access it
    function __construct(BuidingConcern $houseToBuild){
     $this-&amp;gt;house  = $houseToBuild;
    }
   abstract function addComponent($toadd);
   abstract  function removerComponent();
   abstract function chargePrice();

}

class BrickLayers extends Worker{

    function removerComponent(){

        return  ' old blocks removed';
    }

    function addComponent($what){

        return  __CLASS__. $this-&amp;gt;house-&amp;gt;addComponent($what) ;
    }

    function chargePrice(){
        return 'I charged 10,000 ';
    }
}


class Painter extends Worker{

    function removerComponent(){
        return ' remove little part of block where to inset pipe wire';
    }

    function addComponent($what){
        return  __CLASS__. $this-&amp;gt;house-&amp;gt;addComponent($what) ; 
    }

     function chargePrice(){
        return 'I charged 6,800 ';
    }
}

$layers  = new BrickLayers(new House()); 
echo $layers-&amp;gt;addComponent('new block and plaster');
///house is decorated by brick layer
////look at BrickLayers class, does it has access to House class to decorate
///yes, it has extends Worker, so BrickLayers has the same constructor as Worker class 
// so inside any method in BrickLayers class, there is access to  House class
/// call $this-&amp;gt;house whis is defined in Worker

$painter  = new Painter(new House());
echo $painter-&amp;gt;addComponent('remove old paint and added new azure paint');```





&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
    </item>
  </channel>
</rss>
