You are here: Re: php 5 classes: public, protected and private « PHP Programming Language « IT news, forums, messages
Re: php 5 classes: public, protected and private

Posted by Jerry Stuckle on 11/27/06 16:38

jopperdepopper wrote:
>>You should read "can be accessed everywhere".
>>
>>Private members can be accessed by members of the class only.
>>Protected members can be accessed by members of the class or a derived
>>class.
>>Public members can be accessed by anyone, including other classes,
>>functions and any other code.
>
>
>
> Thanks Jerry. I'm trying to make a bit of sense of the php 5 approach
> to classes, and so far having a hard time. I fail to see the 'why'
> behind the 'public, protected and private' and stuff like abstraction,
> interfaces and whatnot. Feels like things are being over-complicated
> somehow... or it's just my being inexperienced on this...
>
> Any other reading material on this suggested, someone?
>

Look for some good books on OO theory and design.

Two of the concepts in OO are 'encapsulation' and 'methods'.

Encapsulation means the internals of an object are managed only by that
object and are not available to anyone else. In PHP these are private
members.

Methods are implemented as functions in PHP. They operate on the object.

The idea is to completely separate the implementation of the class from
the use of it. It means you can change the class any way you want. As
long as the public interface remains the same, it makes no difference.

A good example of this is floating point numbers. They are stored as a

x * 2^y

X is the mantissa, y is the base 2 exponent. For instance, 8 would be
stored as x=1 and y=3, because 8 is 1 * 2^3. But all of this is hidden
behind the scenes; you can do operations on a floating point number such
as add, subtract, print, etc.

And if at some other time PHP changed the implementation to something
else, none of your code would change.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this 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

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