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 19:40

jopperdepopper wrote:
>>Look for some good books on OO theory and design.
>>
>
>
> Thanks Jerry, maybe the php 5 approach is a better implementation than
> the php 4 approach? I have always felt that in php 4 using classes (or
> at least my way of using them) was more a convenient way to organise
> code, grouping some related functions in one class, other related ones
> in another...
>
> Gotta get me some books & hope it's going to be a loooong coooold
> winter ;)
>

Yes, I think it is - but then I've been doing OO programming for a
number of years, both in C++ and Java.

Classes are a good way to organize code - but more importantly, they are
a way of organizing code AND DATA. A properly constructed class should,
as much as possible, manage it's own data independent of other classes
and code.

It's a whole different way of thinking which is usually quite a jump for
experienced programmers. In fact, I find newer programmers typically
have less problems, because structured code techniques are not so deeply
ingrained in their mind. :-)

But it's well worth it; the resulting code can be much more readable and
maintainable.

A good example. I needed to implement some pages based on a database.
However, the particular host being used at the time did not have MySQL
available (they claimed they did, but it wasn't very reliable...).

So I implemented the code in flat files using a class for the data being
displayed, and pages to use that class. Later, when they changed to a
host which had MySQL, all I had to do was go back to the class and
change it to read from a database instead of a flat file. No changes to
the pages were needed at all. Very clean and easy to do, because I
segregated the operations on the data in the class, and used the web
page code just to display the data.


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

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