Hi all
Recently I've been reading /Code Complete/ by Steve McConnell, and in it
he recommends the use of ADTs, or Abstract Data Types, which I have been
thinking about implementing in a major project I am currently embarking on.
Basically the question that I have for the list is this:
If I have a relatively simple class, for example Photo, then why does
McConnell recommend that I do this:
<?php
$caption = $instanceOfPhotoClass->getCaption();
//do something with $caption
$instanceOfPhotoClass->setCaption($caption);
?>
Rather than this:
<?php
$caption = $instanceOfPhotoClass->caption;
// do something with $caption
$instanceOfPhotoClass->caption = $caption;
?>
I'm just looking for some alternative explanations to what McConnell
offers in the book. I can understand that the first example allows me to
"know" when an attribute has been modified... but it annoys me that I
have code like this:
class Photo {
private $caption;
[...]
public function setCaption($newCaption) {
$this->caption = $newCaption;
}
}
It just seems so pointless......
Thanks in advance for any comments.
Jasper
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php