Make it SOLID!
Upcoming SlideShare
Loading in...5
×
 

Make it SOLID!

on

  • 415 views

Os princípios SOLID surgiram para trazer as melhores práticas do desenvolvimento de softwares seguindo o paradigma de orientação a objetos. Nesta Palestra vamos entender de forma prática quais ...

Os princípios SOLID surgiram para trazer as melhores práticas do desenvolvimento de softwares seguindo o paradigma de orientação a objetos. Nesta Palestra vamos entender de forma prática quais são estes princípios e como podemos utilizá-los no nosso dia-a-dia.

Statistics

Views

Total Views
415
Views on SlideShare
412
Embed Views
3

Actions

Likes
9
Downloads
5
Comments
2

1 Embed 3

https://twitter.com 3

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Make it SOLID! Make it SOLID! Presentation Transcript

  • Make itMake it SOLID!SOLID! Luís Otávio Cobucci OblonczykLuís Otávio Cobucci Oblonczyk @lcobucci@lcobucci
  • O queO que nãonão éé SOLID?SOLID?
  • O queO que nãonão éé SOLID?SOLID?
  • RelembrandoRelembrando
  • Baixo acoplamento e alta coesão... RelembrandoRelembrando
  • RelembrandoRelembrando
  • RelembrandoRelembrando Fazer APENAS funcionar é fácil...
  • DecisõesDecisões
  • DecisõesDecisões Linguagem
  • DecisõesDecisões Linguagem Bibliotecas
  • DecisõesDecisões Linguagem Bibliotecas Arquitetura
  • Bad smellsBad smells
  • Bad smellsBad smells Rigidez
  • Bad smellsBad smells Rigidez Fragilidade
  • Bad smellsBad smells Rigidez Fragilidade Imobilidade
  • Bad smellsBad smells Rigidez Fragilidade Imobilidade Complexidade desnecessária
  • Como surgem osComo surgem os bad smells?bad smells?
  • Como surgem osComo surgem os bad smells?bad smells? class UserManager { public function __construct() { /*... */ } public function create($name, $age) { /*... */ } }
  • Como surgem osComo surgem os bad smells?bad smells? public function __construct() { $this->conn = new PDO( 'mysql:host=127.0.0.1;dbname=awesome', 'root', 'ImAGenius' ); }
  • Como surgem osComo surgem os bad smells?bad smells? public function create($name, $age) { $stm = $this->conn->prepare('...'); $stm->execute([$name, $age]); }
  • Como surgem osComo surgem os bad smells?bad smells?
  • Como surgem osComo surgem os bad smells?bad smells? class UserManager { public function __construct() { /*... */ } public function create($name, $age, $responsible) { /*... */ } }
  • Como surgem osComo surgem os bad smells?bad smells? public function __construct() { // (…) $this->logger = new FileLogger('/tmp/users.log'); }
  • Como surgem osComo surgem os bad smells?bad smells? public function create($name, $age, $responsible) { $stm = $this->conn->prepare('...'); $stm->execute([$name, $age]); $this->logger->log(/* … */); }
  • Como surgem osComo surgem os bad smells?bad smells?
  • Principles of OODPrinciples of OOD
  • Principles of OODPrinciples of OOD Class design
  • Principles of OODPrinciples of OOD Class design Package cohesion
  • Principles of OODPrinciples of OOD Class design Package cohesion Package coupling
  • Principles of OODPrinciples of OOD Class design SOLIDSOLID Package cohesion Package coupling
  • SOLID principlesSOLID principles
  • SOLID principlesSOLID principles Single Responsibility principle
  • Single ResponsibilitySingle Responsibility One does not simply have more than a reason to modify a class...
  • Single ResponsibilitySingle Responsibility A class should have one, and only one, reason to change.
  • Single ResponsibilitySingle Responsibility public function __construct() { $this->conn = new PDO( 'mysql:host=127.0.0.1;dbname=awesome', 'root', 'ImAGenius' ); $this->logger = new FileLogger('/tmp/users.log'); }
  • Single ResponsibilitySingle Responsibility public function __construct(PDO $conn, FileLogger $logger) { $this->conn = $conn; $this->logger = $logger; }
  • SOLID principlesSOLID principles Single Responsibility principle Open/Closed principle
  • Open/closedOpen/closed Should be able to extend behaviors, without modifying the class
  • Open/closedOpen/closed public function create($name, $age, $responsible) { $stm = $this->conn->prepare('...'); $stm->execute([$name, $age]); $this->logger->log(/* … */); }
  • Open/closedOpen/closed public function create($name, $age, $responsible) { $this->persist($name, $age); $this->log($name, $responsible); } protected function persist($name, $age) { $stm = $this->conn->prepare('...'); $stm->execute([$name, $age]); } protected function log($name, $responsible) { $this->logger->log(/* … */); }
  • SOLID principlesSOLID principles Single Responsibility principle Open/Closed principle Liskov substitution principle
  • Liskov substitutionLiskov substitution Derived classes must be substitutable for their base classes
  • Liskov substitutionLiskov substitution class UserManager { public function __construct(PDO $conn, FileLogger $logger) { /*... */ } public function create($name, $age, $responsible) { /*... */ } }
  • Liskov substitutionLiskov substitution public function create( UserManager $service, $name, $age ) { return $service->create($name, $age, $this->responsible); }
  • Liskov substitutionLiskov substitution class EmployeeManager extends UserManager { public function create($name, $age, $responsible) { /**/ } protected function persist($name, $age) { /**/ } }
  • Liskov substitutionLiskov substitution class EmployeeManager extends UserManager { public function create($name, $age, $responsible) { if ($age < 18) { throw new InvalidArgumentException(); } parent::create($name, $age, $responsible); } }
  • Liskov substitutionLiskov substitution class EmployeeManager extends UserManager { protected function persist($name, $age) { /**/ } }
  • SOLID principlesSOLID principles Single Responsibility principle Open/Closed principle Liskov substitution principle Interface segregation principle
  • Interface segregationInterface segregation Make fine grained interfaces that are client specific
  • Interface segregationInterface segregation public function __construct(PDO $conn, FileLogger $logger) { $this->conn = $conn; $this->logger = $logger; }
  • Interface segregationInterface segregation public function __construct( DatabasePersister $persister, FileNotifier $notifier ) { $this->persister = $persister; $this->notifier = $notifier; }
  • SOLID principlesSOLID principles Single Responsibility principle Open/Closed principle Liskov substitution principle Interface segregation principle Dependency inversion principle
  • Dependency InversionDependency Inversion Depend on abstractions, not on concretions
  • Dependency InversionDependency Inversion public function __construct( DatabasePersister $persister, FileNotifier $notifier ) { $this->persister = $persister; $this->notifier = $notifier; }
  • Dependency InversionDependency Inversion public function __construct(Persister $persister, Notifier $notifier) { $this->persister = $persister; $this->notifier = $notifier; }
  • SOLID principlesSOLID principles
  • SOLID principlesSOLID principles Classes mais coesas
  • SOLID principlesSOLID principles Classes mais coesas Menos acoplamento
  • SOLID principlesSOLID principles Classes mais coesas Menos acoplamento Menos mudanças
  • Dúvidas?Dúvidas?
  • Obrigado!Obrigado! @lcobucci@lcobucci