Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not a real world example as such, but one Design Pattern where you usually encounter interfaces and abstract classes is the <a href="http://sourcemaking.com/design_patterns/command/php" rel="nofollow noreferrer">Command Pattern</a>. See link for example code.</p> <p>In general, "programming against an interface" is considered good OO practise, because it decouples concrete implementations and let you more easily change them for other implementations, e.g. instead of asking for a specific class</p> <pre><code>public function fn(ConcreteClass $obj) { $obj-&gt;doSomething() } </code></pre> <p>you just ask that it provides a certain set of methods</p> <pre><code>public function fn(MyInterface $obj) { $obj-&gt;doSomething() } </code></pre> <p>Interfaces also help teasing apart large inheritance structures. Because PHP supports only Single Inheritance, you'll often see hierarchies like this:</p> <pre><code>BaseClass -&gt; Logger -&gt; Auth -&gt; User </code></pre> <p>where each of these contains specific aspects used inside these classes. With an interface, you just do</p> <pre><code>User implements Loggable, Authenticable </code></pre> <p>and then include that specific code via Strategy Patterns or Composition/Aggregation, which is ultimately much more maintainable.</p> <p>For a list of predefined interfaces in PHP see my answer to:</p> <ul> <li><a href="https://stackoverflow.com/questions/2757024/where-to-find-template-interfaces/2757058#2757058">where to find &quot;template&quot; interfaces?</a>.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload