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/30/06 13:12

Tony Marston wrote:
> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
> news:n9GdnZYmX_-4EfDYnZ2dnUVZ_q-dnZ2d@comcast.com...
>
>>Tony Marston wrote:
>>
>>>"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
>>>news:bpudnWTDrLPbNPHYnZ2dnUVZ_tudnZ2d@comcast.com...
>>>
>>>
>>>>Tony Marston wrote:
>>>>
>>>>
>>>>>"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
>>>>>news:PeudnRKltLJsufHYnZ2dnUVZ_u2dnZ2d@comcast.com...
>>>>>
>>>>>
>>>>>
>>>>>>Tony Marston wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
>>>>>>>news:j9-dnQB80fVLOvbYnZ2dnUVZ_rOdnZ2d@comcast.com...
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>Tony Marston wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>>"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
>>>>>>>>>news:Ib6dna_BtYQSifbYnZ2dnUVZ_sSdnZ2d@comcast.com...
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>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.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>Intefaces are not necessary in PHP. Once you have defined a method
>>>>>>>>>it is a total waste to time to also define an interface. Interfaces
>>>>>>>>>are a "fix" in those languages as a means of dealing with optional
>>>>>>>>>arguments and statyic typing. PHP has ifferent ways of dealing with
>>>>>>>>>bth of these, therefore interfaces serve no useful purpose.
>>>>>>>>>
>>>>>>>>
>>>>>>>>Ah, the great Tony Marston is back to trolling again.
>>>>>>>>
>>>>>>>>Wrong. In OO terms, the interface is the way to interact with the
>>>>>>>>object. It consists of all public members - both methods (functions,
>>>>>>>>in PHP) and variables. And for derived classes, the base class adds
>>>>>>>>protected members.
>>>>>>>>
>>>>>>>>A PHP interface is something entirely different.
>>>>>>>
>>>>>>>
>>>>>>>I disagree. It is possible to define a function (method) within a
>>>>>>>class,
>>>>>>>then to define a separate thing called an "interface". It is possible
>>>>>>>access
>>>>>>>the function without using the interface, therefore the interface is
>>>>>>>not
>>>>>>>necessary.
>>>>>>>
>>>>>>
>>>>>>Tony,
>>>>>>
>>>>>>You really need to learn about OO before spouting off. In OO terms, an
>>>>>>interface is something entirely different than a PHP interface.
>>>>>
>>>>>
>>>>>How so? All the documentation I have seen describes how an interface
>>>>>simply describes a method which it imlements. If it is possible to
>>>>>access a method (a function in PHP) without going though an interface,
>>>>>ten an interface is not necessary in any language.
>>>>>
>>>>
>>>>You need to understand the difference between an interface as described
>>>>in OO terms and the PHP interface.
>>>>
>>>>The PHP interface defines a set of methods (function) which are required
>>>>by the classes which implement the interface. Java is similar in that
>>>>respect. But both are a subset of the total interface.
>>>
>>>
>>>It is possible to access the method directly without an interface,
>>>therefore an interfae is not necessary.
>>>
>>
>>"Possible" != "CORRECT"
>
>
> That's just your opinion. Where does it say that I *MUST* define and use an
> interface before I can access a class method? Interfaces are optional
> (especuially in PHP) so it is not wrong to excercise the option NOT to use
> them. I can define a class method and access that method without using an
> interface, and that is what I choose to do.
>

When are you going to get it through that pea-sized mind of yours that a
PHP interface is not the same as an interface as defined in OO terms?

In OO terms, a public method is part of the interface. The PHP keyword
interface just defines a set of functions which must be implemented by
the class.

They are two entirely different things.

--
==================
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

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