Fundamental question about ADTs
| From: | Jasper Bryant-Greene | Date: | Fri, 29 Jul 2005 11:35:53 +0000 |
| Subject: | Fundamental question about ADTs | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-219588@lists.php.net to get a copy of this message | ||
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