Is it good for methods to depend on each other inside the class, methods that are encapsulated together? Does this affect unit testing? or the term Unitrefers to the whole class, and not to the classβs own methods.
It is ok to do something like this:
<?php
class foo {
protected $baz;
protected $bar;
private function checkBaz($baz) {
}
private function checkBar($bar) {
}
public function setBaz($baz) {
if($this->checkBaz($baz)){
$this->baz = $baz;
}
}
public function setBar($bar) {
if($this->checkBar($bar)){
$this->bar = $bar;
}
}
}
I think that if I want to use the associated method from this class to another class, I need to rewrite this method a bit, I wandered if it is overhead so that the methods are encapsulated in some way, like inserting functionality into the method parameters, Is it is common practice in OOP or I should stick to the idea that the class is an encapsulation of the method and properties of high cohesion and considers it as a whole reusable and tested Unit.