Reply to Fundamental question about ADTs

Your name:

Reply:


Posted by Jasper Bryant-Greene on 07/29/05 14:35

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация