Can someone please explain to me when is a class useful over a set of functions?
Almost always. Object oriented programming offers many many advantages (that I cannot get into depth on here). There are a few exceptions where you would not use classes, such as utility functions like max() and min() that would be used generically.

The most basic purpose of a class is to define your own 'type' of object. When you create a class you are encapsulating an 'idea' into a set of attributes and behaviors specific to that type.

Designing classes not only offers a great way of organizing code but inevitably forces you to think thoroughly about the logical separation of code and to refine more and more towards an idealized type with well defined and sensible behavior. Conversely non-object oriented programming tends to lack in clarity and intended usage, making it difficult and confusing to use, getting exponentially worse for complex problems.

Classes have methods (functions) that are designed to work specifically on members of that class or perform operations directly related to it. Plain functions, however, have a tendency to be vague and complicated by argument lists. Furthermore they are easier to be misused and can be prone to latent errors.

In the end, it's like driving a car: the engine is neatly hidden under the hood and you don't care or want to know about the internal workings of it. You just want to get in, turn the key and drive. Classes are no different... they provide a simplified user-friendly interface to complex things. It's luxury in programming :)

I would suggest getting some books to learn further, and just start using classes.

Steven J. Walker
Walker Effects
www.walkereffects.com
[EMAIL PROTECTED]

On Monday, June 2, 2003, at 08:31 PM, Vijay Avarachen wrote:

I have been mostly using function in my php code, and lately I have been
curious about classes. I have a vague idea of classes from my C++ class
that I took a few years back. Can someone please explain to me when is a
class useful over a set of functions? I have seen very few code with
classes, so pretty much always stayed away from it.


Thanks,
Vijay Avarachen



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



Reply via email to