/** * If what this method does can not be made obvious from * its name, explain it here. * * @param string $firstname * @return void */ public function changeFirstName($firstName) { // code }
“Shy code - modules that don’t reveal anything unnecessary to other modules and that don’t rely on other modules’ implementations” - The Pragmatic Programmer
public function ship(Product $product, $shippingMethod) { switch ($shippingmethod) { case shipping::shipping_default: $this->defaultshipping($product); break; case shipping::shipping_priority: $this->priorityshipping($product); break; } }
class Car implements VehicleInterface { public function driveTo(Destination $destination) { // start driving } public function swapTires(TyreTypeInterface $tyreType) { // swap tyres } }
class Boat implements VehicleInterface { public function driveTo(Destination $destination) { // start driving } public function swapTires(TyreTypeInterface $tyreType) { throw new BoatHasNoWheelsException(); } }
interface VehicleInterface { public function driveTo(Destination $destination); } interface WheeledVehicleInterface { public function swapTires(TyreTypeInterface $tyreType); }
READING LIST Patterns of Enterprise Application Architecture - Martin Fowler Clean Code - Robert C. Martin Growing Object-Oriented Software, Guided By Tests (the GOOS book) - Steve Freeman & Nat Pryce The Pragmatic Programmer - Dave Thomas & Andy Hunt
VIDEOS Models and Service Layers; Hemoglobin and Hobgoblins - Ross Tuck (https://www.youtube.com/watch?v=3uV3ngl1Z8g) Unbreakable Domain Models - Mathias Verraes (https:// www.youtube.com/watch?v=ZJ63ltuwMaE) The Framework As An Implementation Detail (https:// www.youtube.com/watch?v=0L_9NutiJlc)