|
Posted by Ben Edwards on 01/20/05 18:50
On Thu, 20 Jan 2005 09:37:37 -0500, Jason Barnett
<jason.barnett@telesuite.com> wrote:
> Dustin Krysak wrote:
> > Hi there, I am pretty new to writing classes (and pretty new to PHP
> > itself), but I was wondering what was the best format for constructing
>
> There are a few general patterns that show up time after time. They
> happen so often that there are formal names for them. This isn't really
> a PHP question per se, but a good site for exploring object design in
> PHP is http://phppatterns.com/
Nice idea, shame about the site. I would expect a patterns site to
have a place with a list of the standard patterns, what they are for
and implementation in the target language. This site douse not (or it
douse I cant find it). Anyone know of one that douse.
Ben
> > classes. Now for example, i have written 2 versions of a class that
> > accomplish the exact same thing. And I was just wondering if there are
> > any advantages to either, or even if one was formatted more so to
> > standards. Just wanting to learn it the proper way from the get go. My
> > classes are formatted for use in flash remoting (hence the methodTable
> > stuff - you can ignore it). I guess my question refers more towards the
> > declaration of properties, etc.
>
> Think of declaration of properties and methods as a "contract". When
> something is public it is available to all of PHP. When it is private
> it is only usable by the class that you define it in. When it is
> protected it is a hybrid; it is usable to the class that defined it and
> it can be "inherited" by classes that extend that class.
>
> So, decide what level of access you really *need* for that property /
> method. If a property is only supposed to be modified by class methods
> (for example, a password string) then make it private or possibly
> protected. If everything is public access then there is temptation to
> do something like:
>
> <?php
>
> class myObject {
> public $pubprop = 'I am the starting value. Trust me, even though I
> am public access';
> }
>
> function all_hell_breaks_loose($obj) {
> $obj->pubprop = 'ANARCHY LIVES! PHEAR DA WRAFF OF DA PUBIC PROPS!';
> }
>
> $obj = new myObject();
>
> /** ... 1000's of lines of code ... */
>
> all_hell_breaks_loose($obj);
> print_r($obj);
>
> ?>
>
> --
> Teach a man to fish...
>
> NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
> STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
> STFM | http://www.php.net/manual/en/index.php
> STFW | http://www.google.com/search?q=php
> LAZY |
> http://mycroft.mozdev.org/download.html?name=PHP&submitform=Find+search+plugins
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Ben Edwards - Poole, UK, England
WARNING:This email contained partisan views - dont ever accuse me of
using the veneer of objectivity
If you have a problem emailing me use
http://www.gurtlush.org.uk/profiles.php?uid=4
(email address this email is sent from may be defunct)
Navigation:
[Reply to this message]
|