You are here: Re: To OOP or not to OOP « PHP Programming Language « IT news, forums, messages
Re: To OOP or not to OOP

Posted by Henk verhoeven on 05/29/07 22:32

Gregor schreef:
> This is partially an opinion question. I have some modularization for my
> main site using vanilla PHP. I'm a one-man operation.
>
> Is there any major benefit to learning and using OOP? I have lots of other
> stuff to be spending my limited intelligence learning.
>
>
One thing OOP is great at that is hard to do with procedural code is
hiding different implementations under a common interface. Look for
example to php's PDO (PHP Data Objects, see
http://nl2.php.net/manual/en/ref.pdo.php ). Several classes implement
the PDO interface for different databases. At the start of your script
you only have to instantiate the right class. From then on all the calls
to the PDO objects will be the same, so if you want to make your script
work on a different database, you will not have to go through your
script to change all function calls. (Of course the PDO has it's
limitations, it will not solve incompatibilities between the SQL
dialects of the different databases.

OOP beginners can learn something else from this example too: It is not
inheritance that matters, it's delegation. In the case of your script
using PDO objects, the script is said to delegate to the PDO objects. It
does not inherit from them. It may even be a procedural script. Yet it
uses their functionality in a flexible way: the implementations can
change by using an object of a different class.

Having different implementations for the same service is called
polymorphism. Every OOP method call is a possible place to introduce
polymorphism. Right away, or later on, when new end user demands need to
be met.

If we use an object of a different class, all implementarions defined in
that class come into effect together. So classes bundel
implementations, and therfore they limit flexibility. But using classes
can improve understandability. The CRAFT of object oriented design is to
balance understandability (simplicity) against flexibilty. The ART of
object oriented design is to invent elegant solutions that maximize both.

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.

 

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

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