Upgrade to Pro — share decks privately, control downloads, hide ads and more …

There is an I in SOLID

There is an I in SOLID

Presentation focuses on the "interface seggregation" principle of the SOLID patterns

Tom Van Herreweghe

October 03, 2017
Tweet

More Decks by Tom Van Herreweghe

Other Decks in Programming

Transcript

  1. S Single Responsability Principle O Open/Closed Principle L Liskov Substitution

    Principle I Interface Segregation Principle D Dependency Inversion Principle
  2. SOLID - BETEKENIS? 5 design principes Uncle Bob Martin Doel

    Code flexibeler, begrijpbaarder, onderhoudbaar(der..)
  3. SETUP - BLOGPOST CLASS class BlogPost implements BlogPostInterface { public

    function getTitle() { /* ... */ } public function getContent() { /* ... */ } public function getAuthor() { /* ... */ } public function getSlug() { /* ... */ } }
  4. SETUP - BLOGPOST INTERFACE interface BlogPostInterface { public function getTitle();

    public function getContent(); public function getAuthor(); public function getSlug(); }
  5. SETUP - SLUGIFIER class Slugifier { /* ... */ public

    function createSlug(BlogPostInterface $blog) { $content = $blog->getSlugableContent(); /* ... do some magic ... */ return $slug; } /* ... */ }
  6. UITBREIDING - BLOGPOSTINTERFACE interface BlogPostInterface { public function getTitle(); public

    function getContent(); public function getAuthor(); public function getSlug(); public function getSlugableContent(); }
  7. UITBREIDING - AUTHOR CLASS class Author implements AuthorInterface { public

    function getFirstname() { /* ... */ } public function getLastname() { /* ... */ } public function getFullname() { /* ... */ } public function getSlug() { /* ... */ } public function getSlugableContent() { /* ... */ } }
  8. UITBREIDING - AUTHOR INTERFACE interface AuthorInterface { public function getFirstname();

    public function getLastname(); public function getFullname(); public function getSlug(); public function getSlugableContent(); }
  9. SLUGIFIER - PROBLEEM! class Slugifier { /* ... */ public

    function createSlug(BlogPostInterface $blog) { $content = $blog->getSlugableContent(); /* ... do some magic ... */ return $slug; } /* ... */ }
  10. SLUGIFIER - PROBLEEM! (PART 2) class Slugifier { /* ...

    */ public function createSlug($item) { $content = $item->getSlugableContent(); /* ... do some magic ... */ return $slug; } /* ... */ }
  11. SLUGABLE - SLUGIFIER class Slugifier { /* ... */ public

    function createSlug(Slugable $item) { $content = $item->getSlugableContent(); /* ... do some magic ... */ return $slug; } /* ... */ }
  12. OPLOSSING - BLOGPOST class BlogPost implements BlogPostInterface, Slugable { public

    function getTitle() { /* ... */ } public function getContent() { /* ... */ } public function getAuthor() { /* ... */ } public function getSlug() { /* ... */ } public function getSlugableContent() { /* ... */ } }
  13. OPLOSSING - BLOGPOST INTERFACE interface BlogPostInterface { public function getTitle();

    public function getContent(); public function getAuthor(); }
  14. NOT

  15. OORZAAK class BlogPost implements BlogPostInterface, Slugable { public function getTitle()

    { /* ... */ } public function getContent() { /* ... */ } public function getAuthor() { /* ... */ } public function getSlug() { /* ... */ } public function getSlugableContent() { /* ... */ } }
  16. MULTIPLE INHERITANCE Kan niet in PHP in object context Kan

    wel in PHP: Multiple Interface Inheritance
  17. class BlogPost implements BlogPostInterface { /* ... */ } interface

    BlogPostInterface extends Slugable { /* ... */ }
  18. INTERFACE SEGREGATION PRINCIPLE Opsplitsen interfaces in meer specifiekere Dependen op

    specifiekste interface Meerdere interfaces implementeren = een oplossing Multiple interface inheritance = betere oplossing