classes...whats the use?

General discussions related to php

Moderators: macek, egami, gesf

User avatar
Virtuoso
php-forum Active User
php-forum Active User
Posts: 268
Joined: Mon Jul 21, 2003 7:05 am
Contact:

classes...whats the use?

Postby Virtuoso » Sat Aug 16, 2003 8:28 am

I know how to use simple classes, but still dont see how classes can benefit for me...

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Postby swirlee » Sat Aug 16, 2003 11:43 am

This is always a tough one to explain. I think if you were to learn Java or Python and use them for a few weeks, you'd understand very well why objects are so useful. Even if you're familiar with concepts like DOM (the Document-Object Model used by XHTML) or CSS or JavaScript, you've seen (perhaps without knowing it) the advantages of OOP.

I made a few stabs at trying to describe this succinctly with a few examples, but I couldn't do it. If you start using OOP (perhaps browse PHPClasses.org or try out PHP's new DOM XML functions) on a regular basis, you'll understand the advantages. Barring that, I can only provide you with links to other discussions on the subject. If you search Google for "OOP advantages" or something similar, you'll find plenty. This thread on the evolt mailing is quite an extensive discussion stemming from a question similar to yours. Click on the [thread] link to see the whole thread, which might make it a little easier to navigate.

Sorry I can't provide you with a better answer. When I first was learning OOP (in a Java course), I didn't get it at first, but then one day it just "clicked" and I understood all of the possibilities it provides. Maybe someone else here can better describe its advantages.

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Sat Aug 16, 2003 4:55 pm

I'm not good at all with OOP, but OOP in general lets you organize your code better and make your code more easy to manage and modify.
It's not just classes, there're a lot of things involved. Like inheritance, polimorphism, public and hidden methods...
Maybe you have to start a big project to see the benefits of using it.
There's a whole philosophy in there. 8O
Another link http://www.quiver.freeserve.co.uk/OOP1.htm

User avatar
tryton
New php-forum User
New php-forum User
Posts: 49
Joined: Wed Jul 09, 2003 8:25 am
Location: Joze
Contact:

Postby tryton » Thu Aug 21, 2003 11:01 am

Don't know if you have any programming experience, but here's a suggestion (I did this just the other day), I found a book similar to those Sams or Dummie books about OOP at Barnes and Nobles. It was quite simple how they put it, highly recommend the book to non-programmers. I recommended it to a few students who are entering college as CS majors and will be undertaking the task of learning C/C++.

The thing I love most about OOP is the fact that you can use the same object that completes a task as a base for all the other objects in your program and not have to reinvent the wheel for every instance of the object. Hope this helped.

liquedus
php-forum Active User
php-forum Active User
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada
Contact:

Postby liquedus » Thu Aug 21, 2003 11:45 am

Joan mentions two very powerful words that OO offers inheritance and polymorphism...

to put it into the words of a former prof:

You have a bird, but you want a Penguin but a penguin cannot fly, so why is a penguin a bird?

What he was talking about is inheritance, if you have a Bird class, then you can create all kinds of birds, yellow birds, red birds...... NO MORE CAFFEINE FOR ME! ahahahahahahahhah :twisted:


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 16 guests