title: how interfaces are used for loose coupling?
body: <p>I don't seem to grasp the concept of how interfaces will implement loose coupling? You might find this question to be a duplicate of some other question but I've read many answers related to this topic and I haven't found a satisfactory explanation. </p>
  
  <p>Below is an example of how many developers implement loose coupling.</p>
  
  <pre><code>interface shape {
     public function sayName();
  }
  
  class Circle implements shape {
  
       public function sayName(){
            echo 'Hello my name is circle';
        }
  }
  
  class Square implements shape {
  
       public function sayName(){
            echo 'Hello my name is square';
        }
  }
  
  class Creator {
         public $shape = null;
         public function __construct(Shape $shape){
            $this-&gt;shape = $shape;
         }
  }
  
  $circle = new Creator(new Circle());
  $circle-&gt;sayName();
  
  $square = new Creator(new Square());
  $square-&gt;sayName();
  </code></pre>
  
  <p>In the above example we are using polymorphism of interface to achieve loose coupling. But I don't see that this code is loosely coupled. In the above example the calling code (client) is directly referring to "Circle" and "Square" classes using "new" operator hence creating tight coupling. </p>
  
  <p>To solve this problem we can do something like this. </p>
  
  <p>interface shape {
         public function sayName();
      }</p>
  
  <pre><code>class Circle implements shape {
  
       public function sayName(){
            echo 'Hello my name is circle';
        }
  }
  
  class Square implements shape {
  
       public function sayName(){
            echo 'Hello my name is square';
        }
  }
  
  class Creator {
         public $shape = null;
         public function __construct($type){
            if(strtolower($type) == 'circle'){
               $this-&gt;shape = new Circle();
            } else if(strtolower($type) == 'square'){
               $this-&gt;shape = new Square();
            } else {
               throw new Exception('Sorry we don\'t have '.$type.' shape');
            }
         }
  }
  
  $circle = new Creator('Circle');
  $circle-&gt;sayName();
  
  $square = new Creator('Square');
  $square-&gt;sayName();
  </code></pre>
  
  <p>This example fixes the problems of previous example but we don't use interface at all. </p>
  
  <p>My question is why should I use interface if I can implement loose coupling without it? what benefits would the interface offer in the above scenario? or what problems would I face if I don't use interface in the above example?</p>
  
  <p>Thanks for your help. </p>