<?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>Forem: mohhamedion</title>
    <description>The latest articles on Forem by mohhamedion (@mohhamedion).</description>
    <link>https://forem.com/mohhamedion</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F533998%2Fd66fc94f-5cf0-48fc-bcbf-19bf0efe3166.png</url>
      <title>Forem: mohhamedion</title>
      <link>https://forem.com/mohhamedion</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mohhamedion"/>
    <language>en</language>
    <item>
      <title>Abstract Factory with builder</title>
      <dc:creator>mohhamedion</dc:creator>
      <pubDate>Sat, 05 Dec 2020 22:18:07 +0000</pubDate>
      <link>https://forem.com/mohhamedion/abstract-factory-with-builder-1o30</link>
      <guid>https://forem.com/mohhamedion/abstract-factory-with-builder-1o30</guid>
      <description>&lt;p&gt;Hello, i have a design patterns test, in that test i have to do abstract factory with builder in one program, i am confused because builder and abstract factory are so similar, we can choose bettwen them but i can't see where we can combine them&lt;br&gt;
can someone tell me if i did anything wrong here in this code?&lt;/p&gt;

&lt;p&gt;&amp;lt;?php&lt;/p&gt;

&lt;p&gt;interface YoutubeFactory{&lt;br&gt;
    public function createVideoLibrary();&lt;br&gt;
    public function createMuiscLibrary();&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;class YoutubeFactoryForAdults implements YoutubeFactory {&lt;br&gt;
    public function createVideoLibrary(){&lt;br&gt;
        return new AdultVideoLibrary();&lt;br&gt;
    }&lt;br&gt;
     public function createMuiscLibrary(){&lt;br&gt;
        return new AdultMusicLibrary();&lt;br&gt;
    }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;class YoutubeFactoryForChildren implements YoutubeFactory {&lt;br&gt;
     public function createVideoLibrary(){&lt;br&gt;
        return new ChiledVideoLibrary();&lt;br&gt;
    }&lt;br&gt;
     public function createMuiscLibrary(){&lt;br&gt;
        return new ChiledMusicLibrary();&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
interface ILibrary {&lt;br&gt;
    public function render();&lt;br&gt;
}&lt;br&gt;
class AdultVideoLibrary implements ILibrary {&lt;br&gt;
    public $link;&lt;br&gt;
    public $author;&lt;br&gt;
    public function render(){&lt;br&gt;
        return 'render adult video';&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
class AdultMusicLibrary implements ILibrary {&lt;br&gt;
    public $link;&lt;br&gt;
    public $author;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function render(){
    return 'render adult music';
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;class ChiledVideoLibrary implements ILibrary {&lt;br&gt;
    public $link;&lt;br&gt;
    public $author;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function render(){
    return 'render chiled video';
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
class ChiledMusicLibrary implements ILibrary {&lt;br&gt;
       public $link;&lt;br&gt;
       public $author;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function render(){
    return 'render chiled music';
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//
class YouTubeFactoryBuilder{
    public $factory;

    public function __construct($visitorAge){
        if($visitorAge&amp;gt;=18){
            $this-&amp;gt;factory= new YoutubeFactoryForAdults();   
        }else{
            $this-&amp;gt;factory= new YoutubeFactoryForChildren();   
        }
    }

    public function createNewFactory($factory_object){
         $this-&amp;gt;factory = $factory_object;

    }

    public function getFactory(){
        return $this-&amp;gt;factory;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;///client code&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$bulder = new YouTubeFactoryBuilder(rand(0,100));
$factory= $bulder-&amp;gt;getFactory();
$videoLibrary = $factory-&amp;gt;createVideoLibrary();
$musicLibrary = $factory-&amp;gt;createMuiscLibrary();

 echo $videoLibrary-&amp;gt;render()."\n";
 echo $musicLibrary-&amp;gt;render();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>designpatterns</category>
      <category>php</category>
      <category>abstractfactory</category>
      <category>builder</category>
    </item>
  </channel>
</rss>
