Reply to Re: php 5 classes: public, protected and private

Your name:

Reply:


Posted by Tony Marston on 12/04/06 11:05

"Curtis" <dyer85@gmail.com> wrote in message
news:1165223018.164046.5750@79g2000cws.googlegroups.com...
>> Hi, Curtis,
>
> Hello :)
>
> <snip>
>> If these variables are public, you can never change them. But what
>> happens if you need to - i.e. for performance? Or accuracy?
> <snip>
>> Rather, if you encapsulate the longitude and latitude, making them
>> private, with accessor functions, the data is not hidden - but the
>> implementation is.
>
> I see, I see. All of a sudden, it's like a light bulb turned on in my
> head. I have have experience using OOP in PHP, Perl, JavaScript, and
> very little in Python and C++, but I am nowhere near an expert,
> although I have learned a lot from just trying out code and reading
> documentation. There is a lot to OOP I have yet to learn, so I'll try
> getting the materials by the experts mentioned. ;)
>
> Just to make sure I interpreted your post correctly:
>
> The benefit of encapsulation is doing things like making certain class
> members private, and then utilizing setters/getters so that you can be
> much more flexible in changing your class in the future.

No, encapsulation is not about making everything private, it is about
putting data and the operations which act upon that data into a single
class. The ability to make certain operations or pieces of data private or
protected is OPTIONAL, not MANDATORY.

I am not saying that you MUST NOT make things private/protected, I am simply
arguing against the statement that you MUST use the private/protected
option. The point is that his is entirely OPTIONAL and is a matter of
personal preference.

As for saying that you MUST make all data private and access it through
getters and setters, you obviously haven't read
http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html

--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org

[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

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