Re: oop question
Posted: Wed Jun 24, 2009 10:08 pm
My accessors/mutators are generally just that, solely keeping implementation data away from public access. It's allowed me to change conventions from the C++ prefix underscore for private data to none-underscore which lets me use more descriptive variables, whereas the prefixed underscore always influences me to use brief names, as I found they looked nasty when something like this:
Without the prefix '_' it doesn't anywhere near as bad.
Anyways, an example of mutator/accessor:
I guess what confuses me, is what difference does it make to the SUT whether you inject a mock registry or the real thing, so long as the API is what is expected everything should continue as expected? I wuld like to see an example of when you experience problems with acccessors/mutators over direct access. Essentially mutators/accessors do give you direct access, only through a method interface, as opposed to data -- coming from a C++ background this has always been a no-no -- although many practices from C++ do not persist in PHP so I'm open to new ideas... 
Code: Select all
private $_first_nameAnyways, an example of mutator/accessor:
Code: Select all
class Front{
private $registry = null;
public function setRegistryObject($registry)
{
$this->registry = $registry;
}
public function getRegistryObject()
{
return $this->registry;
}
}