You are here: Re: Object Oriented PHP « PHP Programming Language « IT news, forums, messages
Re: Object Oriented PHP

Posted by Chung Leong on 11/24/05 20:44

Angelos wrote:
> Why do you say that the design is rubbish ? In OO everything can relate
> to anything ... Who says that a logging Class should not relate with a
> Validation Class...

The basic premise of OO is that objects in a program behave as objects
in the real world. A class should only be dependent on classes that are
its constituent parts. A log meant to be used across an application
obviously isn't be a part of the data validator.

In what I consider a proper OO design, the validator class would expose
a connection point that is then plugged into a slot in the logging
class. The two classes remain independent of each other. One broadcasts
signals to any possible listeners, while the other handle signals
emitted by any possible sources. If suddenly I don't want logging, all
I have to do is break the connection. If I want to add another
notification mechanism, I just grab another connection point and stick
it somewhere else. Neither case involves a change to the class.

Of course, a full-on OO treatment is overkill for most PHP apps. Going
through multiple layers of abstractions to echo a line of text is vain.
A half-hearted attempt at OO, I would say though, is pointless and
counterproductive. You have functions defined somewhere that you want
to call--that's procedure oriented programming. Wrapping them in a
class doesn't change anything--the basic approach is still the
same--except now you have a object to worry about.

 

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

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