Re: [PHP] when is OOP a good choice?

2003-02-13 Thread SLanger
Hello

There isn't an easy answer to this but I guess the most important thing 
being that it is easier to maintain in big projects and this makes it more 
robust since you can test in a more modular way. Also it makes it easier 
to reuse code also this seems to be one of those urban legends. At least 
most people I have seen so far tend to throw old code away and reimplement 
the wheel... well its getting better. 
Especially good Frameworkdesign is a lot easier with OO. 
There is one drawback to OOP using PHP at least in version 4. (This is 
supposed to change in 5)
PHP doesn't support the concept of abstract  classes (can be emulated) and 
function overloading (two functions having the same name but different 
signature). This makes it hard to implement polymorphism in some 
situations (IMHO) which is one of the key concepts of OOP. 
If you are coming from a different OO Language like JAVA it tends to screw 
you up that PHP Objects only live for the duration of the script. So you 
have to be sure to recreate objects on every request or you have to use 
sessions in order to preserve Objects. This makes it a bit of a pain IMHO 
to use OO in PHP. 

As I see it (correct me if I'm wrong) in version 4, OO is just a way to 
construct  modular PHP that can be easily extended for custom behaviour.
So to your second point I'd say:
If you have a very complicated and long script, which can be broken down 
into modules, so that each module can function on its own then it would be 
a good choice to create this module as a class. Further if you plan on 
extending the behaviour of this module (add new functionality or override 
some functionality) thenyou have to create it as a class since only OO 
allows you to override the functionality. 
Another pro for OO is when you have modules (objecty/classes) that you are 
reusing very often, but these modules change in functionality it is also a 
good idea to create classes. (Example: DB access, each DB handles access 
differently. So create a base class with a common API for DB access and 
extend the actual DB handling classes from that. When your scirpt uses the 
base class to interface with the DB you can easily switch databases by 
simply switching the implementing class. NOT sure this makes sense ; )) 
On the other hand if you simply need to do something over and over, e.g. 
change characters into entitites and viceversa, a function is better 
suited.

Basically it is a design choice and there is no real pro and contra for 
the one or the other. There are enough people out there that do OO but 
don't really use OO. 

Hope that shed some light on the matter

Stefan 


[PHP] when is OOP a good choice?

2003-02-12 Thread anders thoresson
I've just started to read about - and will soon try to write - object 
oriented code. I think I've got the basics both from the PHP-books I have, 
and from various sources on the web.

But nowhere have I read a good explanation to two of my questions:

1. What are the main benefits from OOP?
2. When is OOP a good choice for a PHP script, and when is ordinary 
functions a better call?

--
anders thoresson

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] when is OOP a good choice?

2003-02-12 Thread Le Yang
Object oriented programming in php has better logic thus is more
suitable for more complex jobs. It also makes maintenance easier,
although you have to write a bit more code

-Original Message-
From: anders thoresson [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, February 12, 2003 3:50 PM
To: [EMAIL PROTECTED]
Subject: [PHP] when is OOP a good choice?

I've just started to read about - and will soon try to write - object 
oriented code. I think I've got the basics both from the PHP-books I
have, 
and from various sources on the web.

But nowhere have I read a good explanation to two of my questions:

 1. What are the main benefits from OOP?
 2. When is OOP a good choice for a PHP script, and when is ordinary 
functions a better call?

-- 
anders thoresson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] when is OOP a good choice?

2003-02-12 Thread php
On 12 Feb 2003 at 21:50, anders thoresson wrote:

 I've just started to read about - and will soon try to write - object 
 oriented code. I think I've got the basics both from the PHP-books I have, 
 and from various sources on the web.
 
 But nowhere have I read a good explanation to two of my questions:
 
  1. What are the main benefits from OOP?
  2. When is OOP a good choice for a PHP script, and when is ordinary 
 functions a better call?


Whenever it's obvious :) ... Actually I think there is a BIG 
difference between simply using object oriented syntax and actually 
*developing* in OO.  Personally, I've been doing OO in Perl for quite 
awhile and use it for PHP as well, but I still do it more in a 
modular sense. imho, OO is a paradigm shift in thinking about how you 
will architect (of course I've seen some work that just throws 
everything in one file and repeats the exact same code every 50 
lines) your application. I'm trying to squeeze myself into fully 
understanding the OO way. I like it. 

In the end, TMTOWTDI, don't get caught by the hype but the apps that 
I've had the most success with evolving and debugging where those 
written more like the OO way than just any old way. 

Peter
Reality is that which, when you stop believing in it, doesn't go 
away.
-- Philip K. Dick


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php