<?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: Mohamed G.Hafez</title>
    <description>The latest articles on DEV Community by Mohamed G.Hafez (@mgamal92).</description>
    <link>https://dev.to/mgamal92</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%2F319754%2Fb8a3d2e8-a1b4-4a08-bfa8-ee542f88829b.jpeg</url>
      <title>DEV Community: Mohamed G.Hafez</title>
      <link>https://dev.to/mgamal92</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mgamal92"/>
    <language>en</language>
    <item>
      <title>Composition Over Inheritance</title>
      <dc:creator>Mohamed G.Hafez</dc:creator>
      <pubDate>Mon, 18 Jul 2022 15:47:52 +0000</pubDate>
      <link>https://dev.to/mgamal92/composition-over-inheritance-1e9</link>
      <guid>https://dev.to/mgamal92/composition-over-inheritance-1e9</guid>
      <description>&lt;p&gt;I will go to the journey with you to explain some design principles to help us to organize, clean our codebase and make it more extendable and maintainable. So let's go with important concept which make our code cleaner and reusable.&lt;br&gt;
What is the composition and when we should use it?&lt;br&gt;
Let me explain and answer this question by example, we all love examples :)&lt;br&gt;
Imagine you have super class called &lt;strong&gt;Duck&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Duck&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;fly&lt;/span&gt;&lt;span class="p"&gt;(){}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;quack&lt;/span&gt;&lt;span class="p"&gt;(){}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(){}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This class has 3 normally methods and it's good for now and it works well for us until your client request a new type of duck to be added called &lt;strong&gt;RubberDuck&lt;/strong&gt;, here you will notice the problem ?&lt;br&gt;
Lets see the problem&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RubberDuck&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Duck&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;fly&lt;/span&gt;&lt;span class="p"&gt;(){}&lt;/span&gt; &lt;span class="c1"&gt;// Why implement this method ?!&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;quack&lt;/span&gt;&lt;span class="p"&gt;(){}&lt;/span&gt; &lt;span class="c1"&gt;// also why too ?!&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(){}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;when you extend from parent Duck class you will inherit a method called fly() and Quack() which are useless to Rubber Duck so what is the solution ? The answer will be to pull out the fly and Quack methods outside Duck class and make a new interface called something like FlyableInterface and QuackablInterface which both have one method for example called fly() at FlyableInterfance and quack at QuackablInterface after that the Duck class can implement these interfaces methods based on its function&lt;br&gt;
so the code will be refactored to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;Interface&lt;/span&gt; &lt;span class="nc"&gt;Flyable&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;fly&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;Interface&lt;/span&gt; &lt;span class="nc"&gt;Quack&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;quack&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the new version of RubberDuck class will implement the new interface method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RubberDuck&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;FlyableInterface&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;QuackableInterface&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;fly&lt;/span&gt;&lt;span class="p"&gt;(){}&lt;/span&gt; &lt;span class="c1"&gt;// from interface&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;quack&lt;/span&gt;&lt;span class="p"&gt;(){}&lt;/span&gt; &lt;span class="c1"&gt;// from interface&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(){}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and the Duck class has one method which in common for all types called display()&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Duck&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(){}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;so here we partially solve the problem but we will notice some problems also after this update but let's discuss that in other articles or write your comments about the problems.&lt;br&gt;
So from the example above we can summarize the meaning of composition by saying it's a process to pull out some methods outside the class and create the interfaces to enable the that class implement the suitable interfaces methods not every method from the super class.&lt;br&gt;
I hope that I succeeded in clarifying the idea, even in a simple way.&lt;br&gt;
Thanks for your reading and sorry for my english as it's not my tongue language&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How your open source works change your career as a developer?</title>
      <dc:creator>Mohamed G.Hafez</dc:creator>
      <pubDate>Wed, 06 Jul 2022 14:33:03 +0000</pubDate>
      <link>https://dev.to/mgamal92/how-your-open-source-works-change-your-career-as-a-developer-21p8</link>
      <guid>https://dev.to/mgamal92/how-your-open-source-works-change-your-career-as-a-developer-21p8</guid>
      <description></description>
      <category>opensource</category>
      <category>github</category>
    </item>
    <item>
      <title>Composition Over Inheritance</title>
      <dc:creator>Mohamed G.Hafez</dc:creator>
      <pubDate>Thu, 06 Aug 2020 22:10:38 +0000</pubDate>
      <link>https://dev.to/mgamal92/composition-over-inheritance-444f</link>
      <guid>https://dev.to/mgamal92/composition-over-inheritance-444f</guid>
      <description>&lt;p&gt;I will go to the journey with you to explain some design principles to help us to organize, clean our codebase and make it more extendable and maintainable. So let's go with important concept which make our code cleaner and reusable.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What is the composition and when we should use it?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let me explain and answer this question by example, we all love examples :)&lt;/p&gt;

&lt;p&gt;Imagine you have super class called Duck&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php 
class Duck 
{
    public function fly(){}
    public function quack(){}
    public function display(){}
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This class has 3 normally methods and it's good for now and it works well for us until your client request a new type of duck to be added called RubberDuck, here you will notice the problem ? Lets see the problem&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
class RubberDuck extends Duck
{
    public function fly(){} // Why implement this method ?!
    public function quack(){} // also why too ?!
    public function display(){}
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When you extend from parent Duck class you will inherit a method called fly() and Quack() which are useless to Rubber Duck so what is the solution ? The answer will be to pull out the fly and Quack methods outside Duck class and make a new interface called something like FlyableInterface and QuackablInterface which both have one method for example called fly() at FlyableInterfance and quack at QuackablInterface after that the Duck class can implement these interfaces methods based on its function&lt;br&gt;
so the code will be refactored to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
Interface Flyable
{
    public function fly();
}
Interface Quack
{
    public function quack();
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now the new version of RubberDuck class will implement the new interface method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php 
class RubberDuck implements FlyableInterface, QuackableInterface 
{
    public function fly(){} // from interface
    public function quack(){} // from interface
    public function display(){}
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and the Duck class has one method which in common for all types called display()&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
class Duck
{
    public function display(){}
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So here we partially solve the problem but we will notice some problems also after this update but let's discuss that in other articles or write your comments about the problems.&lt;br&gt;
So from the example above we can summarize the meaning of &lt;strong&gt;composition&lt;/strong&gt; by saying it's a process to pull out some methods outside the class and create the interfaces to enable the that class implement the suitable interfaces methods not every method from the super class.&lt;br&gt;
I hope that I succeeded in clarifying the idea, even in a simple way.&lt;br&gt;
Thanks for your reading and sorry for my english as it's not my tongue language&lt;br&gt;
You can follow me on &lt;a href="https://twitter.com/mgdev92"&gt;Twitter&lt;/a&gt; or &lt;a href="https://github.com/mgamal92"&gt;Github&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Meet New Challenges</title>
      <dc:creator>Mohamed G.Hafez</dc:creator>
      <pubDate>Tue, 21 Jan 2020 06:55:08 +0000</pubDate>
      <link>https://dev.to/mgamal92/meet-new-challenges-cao</link>
      <guid>https://dev.to/mgamal92/meet-new-challenges-cao</guid>
      <description>&lt;p&gt;Recently I've started my API-Driven PHP Framework. I'm working on it to use in my open source or side projects. If you would like to meet new challenges, learning some new stuff, meet other developers, etc.. You can contribute on &lt;a href="https://github.com/espressoPHP/framework#todo"&gt;espressoPHP&lt;/a&gt; and you are very welcomed :)&lt;/p&gt;

</description>
      <category>php</category>
      <category>opensource</category>
    </item>
    <item>
      <title>How do you manage your all tasks ?</title>
      <dc:creator>Mohamed G.Hafez</dc:creator>
      <pubDate>Sun, 19 Jan 2020 12:05:00 +0000</pubDate>
      <link>https://dev.to/mgamal92/how-do-you-manage-your-all-tasks-5729</link>
      <guid>https://dev.to/mgamal92/how-do-you-manage-your-all-tasks-5729</guid>
      <description>&lt;p&gt;I'm unorganized person. I've tried a lot of task mangement apps but I didn't like any of them. So if anyone like me how to manage/write your tasks for daily job, side projects, etc.. ? &lt;/p&gt;

</description>
      <category>productivity</category>
    </item>
    <item>
      <title>How open source improves a developer skills ?</title>
      <dc:creator>Mohamed G.Hafez</dc:creator>
      <pubDate>Sat, 18 Jan 2020 13:47:18 +0000</pubDate>
      <link>https://dev.to/mgamal92/how-open-source-improves-a-developer-skills-50nj</link>
      <guid>https://dev.to/mgamal92/how-open-source-improves-a-developer-skills-50nj</guid>
      <description>&lt;p&gt;There is an abandoned treasure for every developer. But I discovered it, worked hard on it and the benifits from is very huge. It's an open source contribution. Any developer needs to improve his skills and upgrade them but he don't know how ? reading books ? learning a new techenology ? new language ? so a lot of resources which make the dicision more diffcult. The solution is write any idea (micro framework, simple game, template engine, small package, etc…) and you will learn more than you imagine, you will find yourself searching a lot and it makes you decide what will you need to learn and how. Also that makes you write a code everyday and read a code reguaraly so it will improve your code skills, your reading skill become better because you knew what you need to read and which book to pick. Just block One hour or Two to work on your own application and I promise the results will be amazing! . Open Github then create a new repository without a lot of thinking and start coding, refactor your code, invite your friends or coworkers to review your code and to help you to fix your mistake. Thanks for reading&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Help me to review my PHP framework</title>
      <dc:creator>Mohamed G.Hafez</dc:creator>
      <pubDate>Sat, 18 Jan 2020 13:29:53 +0000</pubDate>
      <link>https://dev.to/mgamal92/help-me-to-review-my-php-framework-48a5</link>
      <guid>https://dev.to/mgamal92/help-me-to-review-my-php-framework-48a5</guid>
      <description>&lt;p&gt;Recently I've started my own PHP framework called espressoPHP to learn some advanced concepts about OOP, SOLID, Design Patterns, Regular Expression, etc.. I need some reviews about code cleaness, organizing, etc. Also if any developer like to contribute with me he will be so welcome because there are a lot of features needs to be done &lt;br&gt;
The Github Link : &lt;a href="https://github.com/espressoPHP/framework"&gt;https://github.com/espressoPHP/framework&lt;/a&gt;&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>php</category>
      <category>framework</category>
    </item>
  </channel>
</rss>
