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

"Hermetryzacja"

 "Hermetryzacja"

Phpers Gliwice lightning talk

Leszek Prabucki

March 18, 2015
Tweet

More Decks by Leszek Prabucki

Other Decks in Technology

Transcript

  1. @cocoders $clinic->setTaxIdNumber('9562307984'); $clinic->setName('Cocoders'); $clinic->addEmployee((new Employee())- >setFirstName('Leszek'))); $clinic->getEmployees()->add((new Employee())->setFirstName('Szymon')); vs $clinic

    = new Clinic('Cocoders', ' 9562307984'); $clinic->hire(new Candidate('Leszek')); $clinic->hire(new Candidate('Szymon')); Gettery i settery a hermetyzacja
  2. class Clinic { public function setName($name) { $this->name = $name;

    return $this; } public function getName() { return $this->name; } //... } @cocoders Anemic model
  3. class Clinic { public function __construct($name, TaxIdNumber $taxIdNumber) { $this->name

    = $name; $this->taxIdNumber = $taxIdNumbr; } public function hire(Candidate $cadidate) { if ($this->employeeAlreadyExists($candidate->getTaxIdNumber())) { throw new \LogicException(sprtinf('We found %s employee already in clinic', $candiate->getTaxIdNumber())); } $this->employees[] = Employee::createFromCandiate($candidate); } } @cocoders Model zhermetyzowany