Hi, I was wondering if anyone can provide a link, or two sets of code, comparing object oriented programming with the use of classes vs. procedural. I understand a little of how object oriented programming works, but if I can see two clear sets of code I think I will understand it better.
I think in C++ you have more control of your program, you have more power. This makes it harder for some people to grasp, and for others, it makes it easier. I think I am one of those people that likes to have great control ;)
This is how I understood OO Programming.
OO programming allows you to manipulate with memory A.K.A 'pointers', 'dynamic memory allocation' and so forth.
I found it very tough to get my head around the real meaning of Object Oriented Programming. As vlad has stated - If you write a 'procedural program' using c++ standard library it will use objects. - even the most simple hello world program uses an object: std::cout
std::cout is an instance of the class ostream (i think - streams are very complex! but do have a quick look at the reference section to verify this). In c++ we can make our own simple (or complex) user types that when used in a program allows you - the programmer - to ignore HOW the type does it's job. It seriously shortens programs, makes code easily understandable and has other benefits.
A Class in an of itself does not make a piece of code 'object oriented'. Only a Class that uses data abstraction AND encapuslation allows you to create an 'Abstract data type'. I just wanted to point out that to start understanding OOP - I recommend you study the key concepts:
1. Data Abstraction
In simple terms you need to think of a class as a static entity - an object is a dynamic representation of that entity during execution of your program.
I cannot explain things very well - but classes are one of the most important topics in c++ After you understand the basics the rest is mainly about language facilities for helping you to write your own classes. So don't just try and rely on sample code to try and figure this out - doing that confused me.
The book C++ Primer 5th Edition shows code that starts out as a 'procedural program'. As it progresses it shows how that same code can be written using the OOP method. It is the best book on c++ that I have read so far. I am not deliberately evading your question.! but i don't believe there is any 'simple code' that will help here but more advanced people might know what example to give you.
Study this fundamental topic from a-z - it will be worth it even if you don't need to write your own types. It will help you to get familiar with using the standard library classes properly.
Object oriented programming is focusing on the data. The procedural programming focuses on the procedure.
Object oriented programming is used when you want to create something that will be used by many people and you want to "hide" its attributes and limit its use to some number of functions (methods). Classes like vector, string or istream/ostream are examples.
I don't know is my explanation is right. I am also new to C++ :/