From what I can gather procedural programming uses procedures and functions or sub routines. It gives a step by step instruction on what to do. Though object oriented on the other hand im not entirely sure. All I have seen is that it uses "objects" and is pretty much the same? Could someone clarify and explain what exactly an object is?
2 Answers
Think of all programming as managing the relationship between two fundamental concepts:
state and behavior. State is the data of your program. Behavior is the logic.
Procedural Programming is based on implementing these two concepts separately. State is held in data structures. Behavior is held in functions (also known as procedures or subroutines). A procedural application therefore passes data structures into functions to produce some output.
Object-Oriented Programming is based on implementing these two concepts together. State and Behavior are combined into one new concept: an Object. An OO application can therefore produce some output by calling an Object, without needing to pass data structures.
Advantages of OO include the potential for information hiding: if a caller needn't pass any data structure, then the caller needn't be aware of any data structure, and can therefore be completely decoupled from the data format.
One fundamental difference between the logic of procedures and the logic of objects is in the way selection is handled. Procedures handle selection using branching logic: the familiar if/else
syntax. Objects prefer to handle selection using polymorphism.
There are similarities between Procedural and OO as well. Both represent an imperative style of programming, meaning they operate by mutating their state (whether inside a data structure or an object) and providing step-by-step instructions on how to compute output. Imperative programming is like writing a recipe.
Finally note that these are idealistic or "pure" definitions. In the real world, paradigms merge. You will rarely, if ever, see a pure OO application. Features from multiple paradigms will be combined, for better or worse.
The difference is that an object holds both state and functionality whereas a function does not hold state.
Consider an enemy in a game. That enemy may be able to do things (i.e.: functionality) such as moving and attacking. At the same time, that enemy also holds data such as its current health.
In procedural programming, you would have to keep passing in the enemy's state as parameters. Object oriented programming differs in that the state is passed to the function (now called a method) automatically.