Click to See Complete Forum and Search --> : Classes??
Napster
03-02-2005, 10:24 PM
Ok, I know a few programming languages like PHP (Obviously) and C++, just to name a few. Anyways most languages like these two allow classes which is all fine but what I could never figure out is, what is a class exactly used for? The only reason I can see is to orgaize variables and functions. I have never seen a reason to use classes and I can do all the same stuff without classes that you can do with them. So could some explain to me exactly what the point of a class is that makes everyone want to use them? Thanks in advance.
dgrinberg
03-02-2005, 10:58 PM
OOP (object oriented programming) is just a different programming philosophy! There have been a number of arguments about OOP vs procedural programming (being the two basic schools of thought).
There are a number of benefits of OOP. Modularisation is one of the main ones.
Have you read any of the articles here on OOP? They are all very good articles and will provide you with much more information, than I could in one post, and even examples.
There are also some good arguments about the different programming philosophies in the article comments, which make for some interesting and humorous reading. :)
bretticus
03-03-2005, 03:12 AM
Understanding abstraction is the key to understanding the benefits of OOP. An example would be a street artist. In order to "mass-produce" drawings, he would not learn how to draw a bear, for example. Instead, he would get good at drawing circles and other basic shapes and then put them together to form the big picture. This is known as abstraction. Modularity is the by-product of abstraction.
Personally, I have found creating database, security, and html form classes very useful (form class handles serialization of Web forms and validation.) I can reuse these classes over and over again. They make producing varied functionality much faster and better streamlined. I can extend these classes and gain instant functionality server-wide in all my Web applications. I am convinced this is the only way to code.
My two cents ;)
jayant
03-03-2005, 03:28 AM
OOP concept came in when it had become very difficult to solve real world problems using procedural programming.
note that, real world problems normally require huge amount of code.
google OOP and you will get lot of information about OOP and its comparison with procedural (both +ve and -ve)
moving to chit-chat forum...
Weedpacket
03-03-2005, 05:42 AM
An object is a thing that has properties and does stuff. A class describes a - well, a class of objects that. The advantage of being able to say "this is a frob and it does this Really Cool Thing™" and be able to actually point to a single distinct chunk of the program, and have the thing behave as a distinct entity can be significant; basically every GUI in the world today is written using OOP techniques because a button is a button and it's still a button even when it's a button with a label.
But, funnily enough, you're not the first to ask.
http://www.phpbuilder.com/board/showthread.php?s=&threadid=10241796
http://www.phpbuilder.com/board/showthread.php?s=&threadid=10231677
http://www.phpbuilder.com/board/showthread.php?s=&postid=10391569
http://www.phpbuilder.com/board/showthread.php?s=&postid=10424374
http://www.phpbuilder.com/board/showthread.php?s=&postid=10220153
http://www.phpbuilder.com/board/showthread.php?s=&threadid=10265547
http://www.phpbuilder.com/board/showthread.php?s=&threadid=10255389
http://www.phpbuilder.com/board/showthread.php?s=&threadid=10255389
Shrike
03-03-2005, 07:20 AM
Encapsulation
Inheritance
Polymorphism
These terms, and not classes and objects, are the best place to start thinking about OOP techniques im my humble, and not so learned, opinion, how many commas can i fit into this sentence, quite a few, I think.
travelbuff
03-03-2005, 10:07 AM
yes shrike - but, how many different types of: punctuation; (e.g., special characters | non-letters) can you fit? :D
Napster: I have gained an interest in OOP and am currently learning it. What got me interested is that I found myself writing larger and larger functions, or nesting functions inside one another, to make my code more reusable or more flexible.
For example, I have a directory on my site. I created a monsterous function to be able to include a varying number of listings from a variable category and display a variable number of characters from the description... just calling the function now requires 7 parameters.
Now what I want to do is create an pair of objects - one to retrieve and one to display the listings. Should be much cleaner and more flexible, and easier to maintain.
davidjam
03-03-2005, 10:36 AM
My favorite feature of objects is $this. For instance:
class hello {
function do() {
$this->something();
if($this->var) { .. }
}
function something() {
$this->var = ..
}
}
Previously the handling of variables and functions was a nightmare. I think if I was a coding prodigy and could code as easily and quickly as breathing, I might prefer procedural style, but object style has restored my sanity. My .0002¢ :)
@ $this->point, of all the # of things I could say: regardless of the % of the whole or it's $ value & etc.; * note this (or this) -- and this! -- what in fact does it = to add "this" + 'that' whether less than [ < ] or greater than { > } ? /me thinks... | \me babbles :~)
pohopo
03-03-2005, 02:35 PM
For the reasons mentioned above I create classes every time for every application. And creating a class is just one small piece in OOP. Creating a class by itself and throwing in a bunch of functions is not what the class was designed for so I can see how some would consider it a waste.
And a class is a blueprint used to create an object. A class holds no values or has a state. So when you need an object you create an instance of a class.
If you are graphic designer doing light programming with dreamweaver I would not worry about this stuff. If you want to do larger development project then using an object oriented style will reap huge rewards.
PHP Builder
Copyright Internet.com Inc. All Rights Reserved.