Sequential coupling is where you create a class that has methods that must be called in a particular order. Method names that start with init
, begin
, or start
may be indicative of this behavior; this may be indicative of an anti-pattern depending on the context. Sometimes, engineers use cars to explain abstract concepts, here I'll do the same.
For example, take the following class:
<?php class BadCar { private $started = false; private $speed = 0; private $topSpeed = 125; /** * Starts car. * @return bool */ public function startCar(): bool { $this->started = true; return $this->started; } /** * Changes speed, increments by 1 if $accelerate is true, else decrease by 1. * @param $accelerate * @return bool * @throws Exception */ public function changeSpeed...