![Page 1: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/1.jpg)
Don’t Be STUPIDGrasp SOLID!
Anthony Ferrara
![Page 2: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/2.jpg)
Let’s TalkObject
OrientedProgramming
![Page 3: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/3.jpg)
WhatIs An
Object?
![Page 4: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/4.jpg)
Classic View
Object == Physical “Thing”
![Page 5: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/5.jpg)
Classic View
Object == Physical “Thing”
Methods == Actions on “Thing”
![Page 6: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/6.jpg)
Classic View
Object == Physical “Thing”
Methods == Actions on “Thing”
Properties == Description of “Thing”
![Page 7: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/7.jpg)
Animal
MammalBird Fish
CatCow Dog
Lion Feline Cheetah
![Page 8: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/8.jpg)
![Page 9: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/9.jpg)
Classic View
$lion = new Lion;$lion->roar();$lion->walkTo($point);$lion->hunt($zebra);$lion->sleep();
![Page 10: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/10.jpg)
Is This Realistic?
![Page 11: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/11.jpg)
Classic View
$lion = new Lion;$lion->roar();$lion->walkTo($point);$lion->hunt($zebra);$lion->sleep();
![Page 12: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/12.jpg)
(9 Months Later)
![Page 13: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/13.jpg)
Classic View
$lion = new Lion;$lion->roar();$lion->walkTo($point);$lion->hunt($zebra);$lion->sleep();
![Page 14: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/14.jpg)
Classic View
$lion = new Lion;$lion->roar();$lion->walkTo($point);$lion->hunt($zebra);$lion->sleep();
Does A Lion Have A Button To Make It Roar?
![Page 15: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/15.jpg)
Classic View
$lion = new Lion;$lion->roar();$lion->walkTo($point);$lion->hunt($zebra);$lion->sleep();
Does A Lion Have A Button To Make It Roar?What Does It
Mean For An Object To “Hunt”?
![Page 16: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/16.jpg)
Classic View
$lion = new Lion;$lion->roar();$lion->walkTo($point);$lion->hunt($zebra);$lion->sleep();
Does A Lion Have A Button To Make It Roar?What Does It
Mean For An Object To “Hunt”?
What Is A Lion In Relation To Our Application?
![Page 17: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/17.jpg)
The Classical Model Is Easy To
Understand
![Page 18: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/18.jpg)
![Page 19: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/19.jpg)
The Classical Model Is
Completely Impractical
![Page 20: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/20.jpg)
“Modern” View
Object == Collection Of (Related) Behaviors
![Page 21: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/21.jpg)
“Modern” View
Object == Collection Of (Related) Behaviors
Methods == Behavior
![Page 22: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/22.jpg)
“Modern” View
Object == Collection Of (Related) Behaviors
Methods == Behavior
Properties == Details Of Behavior
![Page 23: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/23.jpg)
Classic View == “(conceptually) is a”
Modern View == “behaves as a”
![Page 24: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/24.jpg)
interface Number {
function getValue(); function __toString();
function add(Number $n); function subtract(Number $n);
function equals(Number $n); function isLessThan(Number $n); function isGreaterThan(Number $n);
}
![Page 25: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/25.jpg)
Number
IntegerFloat Decimal
longshort long long
unsigned signed
![Page 26: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/26.jpg)
But Wait!
![Page 27: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/27.jpg)
We Don’t Even Need Inheritance
![Page 28: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/28.jpg)
All We Need IsPolymorphism
And Encapsulation
![Page 29: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/29.jpg)
![Page 30: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/30.jpg)
Polymorphism
Behavior Is Determined Dynamically
“Dynamic Dispatch”
![Page 31: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/31.jpg)
Procedural Code
if ($a instanceof Long) { return new Long($a->getValue() + 1);} elseif ($a instanceof Float) { return new Float($a->getValue() + 1.0);} elseif ($a instanceof Decimal) { return new Decimal($a->getValue() + 1.0);
}
![Page 32: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/32.jpg)
Polymorphic Code
return $int->add(new Integer(1));
![Page 33: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/33.jpg)
Polymorphic Code
class Integer implements Number { public function add(Number $a) { return new Integer( $this->getValue() + (int) $a->getValue() ); }}
![Page 34: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/34.jpg)
Polymorphic Code
class Float implements Number { public function add(Number $a) { return new Float( $this->getValue() + (float) $a->getValue() ); }}
![Page 35: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/35.jpg)
![Page 36: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/36.jpg)
Encapsulation
Behavior Is Completely Contained By The Object’s API
(Information Hiding)
![Page 37: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/37.jpg)
Procedural Code
if (5 == $number->value) { print “Number Is 5”;} else { print “Number Is Not 5”;}
![Page 38: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/38.jpg)
Encapsulated Code
if ($number->equals(new Integer(5))) { print “Number Is 5”;} else { print “Number Is Not 5”;}
![Page 39: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/39.jpg)
Encapsulated Codeclass Decimal implements Number { protected $intValue; protected $exponent; public function equals(Number $a) { if ($a instanceof Decimal) { // Compare Directly } else { // Cast } }}
![Page 40: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/40.jpg)
![Page 41: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/41.jpg)
Behavior Is Defined By The
API
![Page 42: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/42.jpg)
Two Types Of Primitive APIs
Interfaces (Explicit)
![Page 43: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/43.jpg)
Two Types Of Primitive APIs
Interfaces (Explicit)
Duck Typing (Implicit)
![Page 44: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/44.jpg)
If an Object Is A Collection Of Behaviors...
![Page 45: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/45.jpg)
What Is A Collection Of
Classes/Objects?
![Page 46: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/46.jpg)
APIs
Method
![Page 47: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/47.jpg)
APIs
Method MethodMethod
Class
![Page 48: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/48.jpg)
APIs
Method MethodMethod
Class ClassClass
Package
![Page 49: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/49.jpg)
APIs
Method MethodMethod
Class ClassClass
Package PackagePackage
Library
![Page 50: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/50.jpg)
APIs
Method MethodMethod
Class ClassClass
Package PackagePackage
Library
Framework
LibraryLibrary
![Page 51: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/51.jpg)
![Page 52: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/52.jpg)
What Makes A Good API?
![Page 53: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/53.jpg)
A Good APIDoes One Thing
![Page 54: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/54.jpg)
A Good APINever Changes
![Page 55: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/55.jpg)
A Good APIBehaves Like Its
Contract
![Page 56: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/56.jpg)
A Good APIHas A Narrow Responsibility
![Page 57: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/57.jpg)
A Good APIDepends Upon Abstractions
![Page 58: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/58.jpg)
And That’sSOLIDCode
![Page 59: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/59.jpg)
S - Single Responsibility Principle O- L - I - D-
A Good API Does One
Thing
![Page 60: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/60.jpg)
![Page 61: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/61.jpg)
![Page 62: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/62.jpg)
S - Single Responsibility Principle O- Open / Closed Principle
L - I - D-
A Good API Never Changes
![Page 63: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/63.jpg)
![Page 64: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/64.jpg)
![Page 65: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/65.jpg)
![Page 66: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/66.jpg)
![Page 67: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/67.jpg)
![Page 68: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/68.jpg)
S - Single Responsibility Principle O- Open / Closed Principle
L - Liskov Substitution Principle
I - D-
A Good API Behaves Like Its Contract
![Page 69: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/69.jpg)
![Page 70: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/70.jpg)
![Page 71: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/71.jpg)
![Page 72: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/72.jpg)
S - Single Responsibility Principle O- Open / Closed Principle
L - Liskov Substitution Principle
I - Interface Segregation Principle
D-
A Good API Has A Narrow Responsibility
![Page 73: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/73.jpg)
![Page 74: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/74.jpg)
S - Single Responsibility Principle O- Open / Closed Principle
L - Liskov Substitution Principle
I - Interface Segregation Principle
D- Dependency Inversion Principle
A Good API Depends Upon Abstractions
![Page 75: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/75.jpg)
![Page 76: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/76.jpg)
![Page 77: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/77.jpg)
S - Single Responsibility Principle O- Open / Closed Principle
L - Liskov Substitution Principle
I - Interface Segregation Principle
D- Dependency Inversion Principle
![Page 78: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/78.jpg)
Note That SOLID Does Not Dictate
What Is Good OOP
![Page 79: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/79.jpg)
SOLID Emerges From Good OOP
![Page 80: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/80.jpg)
![Page 81: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/81.jpg)
So, What Makes A Bad API?
![Page 82: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/82.jpg)
Global Variables(Spooky Action At A Distance)
![Page 83: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/83.jpg)
Depending OnSpecifics Of An Implementation
![Page 84: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/84.jpg)
Hidden Dependencies
![Page 85: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/85.jpg)
Unhealthy Focus On Performance
![Page 86: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/86.jpg)
Poorly Named APIs
![Page 87: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/87.jpg)
Duplication
![Page 88: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/88.jpg)
And That’sSTUPID
Code
![Page 89: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/89.jpg)
S - Singletons
T -U -P -I -D-
Global Variables(Spooky ActionAt A Distance)
![Page 90: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/90.jpg)
![Page 91: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/91.jpg)
S - Singletons
T - Tight Coupling
U -P -I -D-
Depending On Specifics Of An
Implementation
![Page 92: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/92.jpg)
![Page 93: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/93.jpg)
S - Singletons
T - Tight Coupling
U - Untestable Code
P -I -D-
Hidden Dependencies
![Page 94: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/94.jpg)
![Page 95: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/95.jpg)
S - Singletons
T - Tight Coupling
U - Untestable Code
P - Premature Optimization
I -D-
Unhealthy Focus On Performance
![Page 96: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/96.jpg)
![Page 97: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/97.jpg)
S - Singletons
T - Tight Coupling
U - Untestable Code
P - Premature Optimization
I - Indescriptive Naming
D-
Poorly Named APIs
![Page 98: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/98.jpg)
![Page 99: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/99.jpg)
S - Singletons
T - Tight Coupling
U - Untestable Code
P - Premature Optimization
I - Indescriptive Naming
D- Duplication
Duplication
Duplication
DuplicationDuplication
Duplication
DuplicationDuplication
Duplication
![Page 100: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/100.jpg)
![Page 101: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/101.jpg)
S - Singletons
T - Tight Coupling
U - Untestable Code
P - Premature Optimization
I - Indescriptive Naming
D- Duplication
![Page 102: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/102.jpg)
STUPID Embodies
Lessons Learned From Bad OOP
![Page 103: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/103.jpg)
What Good OOP Gives You
Modular CodeReusable CodeExtendable CodeEasy To Read CodeMaintainable CodeEasy To Change CodeEasy To Understand CodeClean Abstractions (mostly)
![Page 104: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/104.jpg)
What Good OOP Costs You
Tends To Have More “Layers”Tends To Be Slower At RuntimeTends To Have Larger CodebasesTends To Result In Over-AbstractionTends To Require More Effort To WriteTends To Require More Tacit Knowledge
![Page 105: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/105.jpg)
Let’s Look At Some Code!
![Page 106: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/106.jpg)
interface Car {
public function turnLeft(); public function turnRight(); public function goFaster(); public function goSlower(); public function shiftUp(); public function shiftDown(); public function start();
}
![Page 107: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/107.jpg)
interface Steerable { public function steer($angle);}interface Acceleratable { public function accelerate($amt);}interface Shiftable { public function shiftDown(); public function shiftUp();}
![Page 108: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/108.jpg)
Let’s Look At Drupal Code!
![Page 109: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/109.jpg)
interface MailSystemInterface {
public function format(array $message);
public function mail(array $message);
}
![Page 110: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/110.jpg)
interface MailSystemInterface {
public function format(array $message);
public function mail(array $message);
}
What Responsibility?
![Page 111: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/111.jpg)
interface MailSystemInterface {
public function format(array $message);
public function mail(array $message);
}
What Responsibility?
Formatting Messages
![Page 112: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/112.jpg)
interface MailSystemInterface {
public function format(array $message);
public function mail(array $message);
}
What Responsibility?
Formatting Messages
Encoding Messages
![Page 113: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/113.jpg)
interface MailSystemInterface {
public function format(array $message);
public function mail(array $message);
}
What Responsibility?
Formatting Messages
Encoding Messages
Assembling Headers
![Page 114: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/114.jpg)
interface MailSystemInterface {
public function format(array $message);
public function mail(array $message);
}
What Responsibility?
Formatting Messages
Encoding Messages
Assembling Headers
Calling Sendmail
![Page 115: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/115.jpg)
interface MailSystemInterface {
public function format(array $message);
public function mail(array $message);
}
What Responsibility?
Formatting Messages
Encoding Messages
Assembling Headers
Calling Sendmail
Setting INI settings…?
![Page 116: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/116.jpg)
interface MailSystemInterface {
public function format(array $message);
public function mail(array $message);
}
What Responsibility?
Open For Extension?
![Page 117: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/117.jpg)
interface MailSystemInterface {
public function format(array $message);
public function mail(array $message);
}
What Responsibility?
Open For Extension?
Edits Require Copy/Paste
![Page 118: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/118.jpg)
interface MailSystemInterface {
public function format(array $message);
public function mail(array $message);
}
What Responsibility?
Open For Extension?
Liskov Substitution...
![Page 119: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/119.jpg)
interface MailSystemInterface {
public function format(array $message);
public function mail(array $message);
}
What Responsibility?
Open For Extension?
Liskov Substitution...
One Interface...
Many Responsibilites
![Page 120: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/120.jpg)
interface MailSystemInterface {
public function format(array $message);
public function mail(array $message);
}
What Responsibility?
Open For Extension?
Liskov Substitution...
One Interface...
What Dependencies?
![Page 121: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/121.jpg)
interface MessageFormatter { public function format(Message $message);
}interface MessageEncoder { public function encode(Message $message);
}interface MessageTransport { public function send(Message $message);
}
![Page 122: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/122.jpg)
class MailSystem { public function __construct( MessageFormatter $messageFormatter, MessageEncoder $messageEncoder, MessageTransport $messageTransport
) {} public function mail(Message $message);
}
![Page 123: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/123.jpg)
Principle Of
GoodEnough
![Page 124: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/124.jpg)
![Page 125: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/125.jpg)
![Page 126: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/126.jpg)
![Page 127: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/127.jpg)
![Page 128: Don't Be STUPID, Grasp SOLID - DrupalCon Prague](https://reader034.vdocuments.us/reader034/viewer/2022052619/555a080fd8b42aa8098b538b/html5/thumbnails/128.jpg)