Practical Explanation : Can anyone Explain the difference between POPS and OOPS with Example?

我是研究僧i 提交于 2019-12-08 12:06:15

问题


I visited so many sites about the differences between Procedular Oriented Programming and Object Oriented Programming , but I did not get Practical answer .

Everyone is saying theoritical answer .

Can anyone give Practical Explanation for this ?


回答1:


Procedural programming is a list or set of instructions telling a computer what to do step by step and how to perform from the first code to the second code.

the best example of a procedural language is C

for e.g here is a python code for procedural programming (any code without oops):

x = int(input('enter a number: '))

def even_odd(x):
    if x%2 == 0:
        print('even')
    else:
        print('odd')

even_odd(x)

Object oriented programming is the style of programming which uses classes and objects to wrap your code and data which helps to use lesser code and at only one place.

every modern language uses oop

for e.g:

class test:
    # your code here along with variables and functions
    x = 'something' #some code
    def test_func(): # some function 
        #your function code here

obj = test()  #this is the object created for the above class which will be used to access the data inside a class

theoretically, as a real world example I think that even god also uses object oriented programming, maybe he first created a parent class called living things which contains exact same properties like exact 2 eyes, 2 hands, one mouth etc, and then he inherited more subclasses like human being, tiger, rat from the same parent class ;)



来源:https://stackoverflow.com/questions/24360230/practical-explanation-can-anyone-explain-the-difference-between-pops-and-oops

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!