Posted 17 April 2007 - 05:58 PM
Let's start out with this question.....If functions are not in a class, then where are they?
The concept of using classes is so that you can have chunks of code that are independent of each other, but can be put together in such a way that they make a whole program. Simple programs only consist of one class. All classes are objects, or rather, all objects are created from classes. An object is an instance of a class, and all Objects have fundamental methods, or functions, associated with them, which is maybe why you are under the impression that functions don't have to be in classes.
One uses multiple classes when a program needs to perform multiple, unrelated functions. Take this web page as a loose example. One class would be to display the stats at the bottom of the page. One class would generate the list of forums. One class generates the text boxes where you make responses. One class interacts with the database. None of these classes know anything about each other. A final class assembles all of the information and displays it as a web-page. In reality, there are dozens and dozens of classes that make up a complex program.
Does that explain it any better? Understanding classes, objects, and instances is incredibly confusing at first.... at least it was for me.