Reply to Re: [PHP] Fundamental question about ADTs

Your name:

Reply:


Posted by Miles Thompson on 07/29/05 14:46

Because the OOP religion requires everything to be done with methods?

Remember CC comes from the MSFT world, not the PHP corner of it. And in the
larger world, public properties of your class, such as Caption, have
corresponding local vars such as m_caption. That is, Caption is not
manipulated directly by its class, and can only be set or read outside of
the class through the class's set and get methods.

Seems a bit cumbersome, but does allow the class to be protected against
dirty data by checking anything passed to it throug
InstanceofCaptio=>SEt($somestring).

Hope this is helpful. In the Visual FoxPro world the caption, if it was
public, could be set with CaptionInstance.Caption = somevar.

Regards - Miles

At 08:35 AM 7/29/2005, Jasper Bryant-Greene wrote:
>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
>

[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

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