DIFFERENCE BETWEEN PROCEDURAL AND OBJECT ORIENTED PROGRAMMING LANGUAGES | survnor.blogspot.com
One way to explain the difference between procedural and object-oriented programming is to use an analogy. Imagine that you want to make a cake. In procedural programming, you would follow a series of steps or instructions, such as:
1. Preheat the oven to 180°C.
2. Mix flour, sugar, eggs, butter, and baking powder in a bowl.
3. Grease a cake pan and pour the batter into it.
4. Bake the cake for 25 minutes or until golden brown.
5. Let the cake cool down and decorate it with frosting and sprinkles.
In object-oriented programming, you would think of the cake as an object that has data (such as ingredients, shape, size, color, and flavor) and behavior (such as mixing, baking, cooling, and decorating). You would create a class called Cake that defines the data and behavior of all cakes. Then you would create an instance of the Cake class, which is a specific cake object that you can customize with your own data and behavior. For example:
Cake myCake = new Cake(); // create a new cake object
myCake.setIngredients("flour", "sugar", "eggs", "butter", "baking powder"); // set the ingredients data
myCake.setShape("round"); // set the shape data
myCake.setSize("large"); // set the size data
myCake.setColor("yellow"); // set the color data
myCake.setFlavor("vanilla"); // set the flavor data
myCake.mix(); // call the mix behavior
myCake.bake(180, 25); // call the bake behavior with parameters for temperature and time
myCake.cool(); // call the cool behavior
myCake.decorate("frosting", "sprinkles"); // call the decorate behavior with parameters for topping and decoration
The main difference between procedural and object-oriented programming is that in procedural programming, you focus on the sequence of actions or instructions that are performed to achieve a task, while in object-oriented programming, you focus on the objects that represent the entities or concepts involved in the task and how they interact with each other. Some of the advantages of object-oriented programming over procedural programming are:
- It allows you to model complex systems more naturally and intuitively by using real-world concepts and entities.
- It promotes code reuse and modularity by allowing you to create classes that can be inherited or extended by other classes.
- It provides data abstraction and encapsulation by hiding the internal details of an object from other objects and exposing only the relevant data and behavior.
- It supports polymorphism and dynamic binding by allowing you to use different implementations of an object's behavior depending on its type or context.
SOME PROCEDURAL-ORIENTED PROGRAMMING LANGUAGES: