Ok, this is a bit long.
If you are doing some small application programming, then the benefits of using classes may not be that obvious to you. However, as your project gets larger, you will realize that the abstraction that the classes provide helps you tackle the problem better.
For instance, let's say that your project is developing a bank account server database application. Let's say that the requirements are as follow:
[ol][li]Basic input/output mechanism to change and get the accounts[/li]
[li]Able to detect invalid/bogus/redundant/corrupt accounts[/li]
[li]Some printing and print preview capability[/li]
[li]Some security (password) identification[/li]
[li]Back-up mechanism[/li]
[li]Ability to upgrade existing data structure (for future application upgrade)[/li]
[li]Leeway for update/patch[/li]
[li]Ability to connect with client programs[/li]
[/ol]
One way to tackle the problem is to do a linear programming (the C style programming). Just write the necessary functions for all those features, then write a main() function where all those sub-functions are brought into play.
Pros: Simple
Cons: As your program gets longer, the source codes get very messy. They become less readeable to other programmers who will continue your work (or even to you when you are called back several months -in my case was years- later to fix/adjust your codes).
An alternate approach is to use an Object Oriented approach. In our case, we can create several classes, such as Database Manager (to handle IO on the database), Security Manager (to handle authentication and such), Printing Manager (to handle printing), Update Manager (to handle future update and data conversion), Task Scheduler (to handle timing for scheduled task such as scheduled back-up), Connection Manager (for remote logon).
Pros: By using objects, you can see clearly who do what. In the future, if you need to re-learn your codes, you can read the codes easily. Also, you can design some of your classes to be reusable (such as file IO, TCP/IP connection, Printing, etc.) so that for future projects, you can just reuse these classes instead of rewriting them from a scratch. In addition, object oriented approach helps you keep track of your memory allocation easily. You can see the variables that each class is responsible for and deallocate them properly at the appropriate destructor.
Cons: Slightly more complicated and time consuming. New programmers can get carried away with fancy OOP features.
Furthermore, in the real world, the requirements are not so easily defined. Most often users don't really know what they want. So we, software engineers, often have to define and redefine the requirements for the application. Often, we may feel like adding features while halfway working on the project, which sometimes require a lot of changes in the existing codes. If you are doing linear programming in a big project, it gets very very messy as you are traversing from one part of the codes to another. In OO apporach, you know exactly what class you need to alter.
However, OO approach is not necessarily better. Using classes does not solve all the problems. I have seen new programmers make classes out of everything and inherit them to death. I believe that you should know both approaches and use the one that suits your needs.
(I generally find that it's better to use struct to group simple data rather than using a class with a bunch of set/get methods. In my opinion, those set/get methods create unnecessary overhead.)
Hope this helps.
Zech