Let me give a simple example of how process-oriented programming work. Consider the case where we want to describe sale state of a shop. Say we have three items: pen, pencil, others.
Process oriented:
sale:
num_pen = num_pen -1
num_pencil = num_pencil -1
purchase:
num_pen = num_pen + 10
num_pencil = num_pencil+20
Object oriented:
class shop:
pen
pencil
others
def sale(type, num):
def purchase(type, num):
Advantage of object-oriented programming:
1.Code reuse.
We can easily see from above that object-oriented programming is more human friendly. And by inheritance of class, we can derive tons of subclass that have similar properties or can share some same methods.
2.Encapsulation.
One can use object oriented programs without knowing one thing before looking at it. This means, as long as we know the type contract, we can call the program and get what we want to get in few lines.
Additionally, we can also prevent other programmers from tampering our programs since it hides the variables quiet well.
3.Design benefits.
When a program reaches certain size, it is easier to program oop rather than non-object-oriented programming. It is because oop forces the programmers to write programs with more focus design intention, which means it is less likely to be a huge law.