Page 1 of 1

Benefits of Classes

Posted: Wed Dec 05, 2007 4:52 am
by Inkyskin
Hi all, I have a question - I know that classes are useful for plugging into many different projects without much or any modification etc, but do they have any benefit over a standard set of functions that you may have on every page via an include? Are there any speed or load savings?

I can't seem to find any information anywhere that discusses the benefits of classes...

Posted: Wed Dec 05, 2007 5:20 am
by Bon Bon
I use classes so that I get paid more at work by my boss, it also prevents him from having any understanding at all of how things work. This benefits me as it means I can do what the hell I want as long as the job gets done. :lol:

Posted: Wed Dec 05, 2007 5:23 am
by Rovas
Being reusable is one the main avantages of a class. You can also extend the functionality of a existing class.
A well written class can be reusable in many projects and be fast as same time. Depends much on your skills.
Classes vs functions is a very debate subject on the internet I' m curios how you didn' t find anything.
Each has it' s area where is strongest:
functions in mediums where is need that a lot information is passed very fast between client and server (includes server talking to each other), a simple website;
classes where the code can be reused, extended, etc like in big projects or a complex application .

Posted: Wed Dec 05, 2007 5:25 am
by Inkyskin
Thanks, thats a lot clearer now - most of the information I could find was just about how to write a class, not discussing it's merits.

Posted: Wed Dec 05, 2007 5:27 am
by Rovas
Bon Bon post is very enlightning.

Posted: Wed Dec 05, 2007 8:24 am
by superdezign
For you to understand the usefulness of classes, you should understand what OOP is. OOP means that your application is based on objects with attributes and capabilities. OOP became popular because it allows us to think in a more worldly mindset. With procedural programming, you think in terms of actions and commands. With OOP, you think in terms of communication and responsibilities.

Also, if you look into object-oriented design (not programming, just design) you'll notice that classes can solve all sort of problems with the use of design patterns.

Posted: Wed Dec 05, 2007 11:30 am
by Christopher
The most important thing about classes is that first and foremost they are DATA. You can achieve a bad replica of a class by passing a struct around to a library of functions. But classes create a namespace with variables that are private to that library of functions. That data protection, which follows the same idea as not using global variables, is central to classes.

When you develop using OO you should be thinking of the data first, then write functions to work on that data.

The next step is to think of the result/behavior you want first, second write a test that specifies it, then define the data, and finally the code.