面向过程和面向对象

在面向过程结构化编程中,程序被分为“数据结构”和“算法”两部分,可以说,在C语言中,我们实际在操纵数据。而面向过程语言大大强化了“数据结构”这个概念,并让其达到了可称之为“对象”的水平。对象是由数据和允许的操作构成的封装体,从而面向对象语言更安全也更稳定。
在面向对象中,核心是"对象"即由数据和允许的操作构成的封装体,而面向过程中的核心为“算法”。

Procedural Programming can be defined as a programming model which is derived from structured programming, based upon the concept of calling procedure. Procedures, also known as routines, subroutines or functions, simply consist of a series of computational steps to be carried out. During a program’s execution, any given procedure might be called at any point, including by other procedures or itself.

面向过程是计算步的集合,从开始到结束(自顶而下),所有的函数都可调用,只为完成计算,因而不安全,其中函数比数据更重要,不基于现实世界,且数据不可变。

Object oriented programming can be defined as a programming model which is based upon the concept of objects. Objects contain data in the form of attributes and code in the form of methods. In object oriented programming, computer programs are designed using the concept of objects that interact with real world. Object oriented programming languages are various but the most popular ones are class-based, meaning that objects are instances of classes, which also determine their types.

面向对象不在乎开始和结束(自底而上),其他与面向过程相反。
面向过程是主要关心在已有事物上加以新的操作,而面向对象主要在已有事物上添加新的类(对象)。
python代码

#!/usr/bin/python
# -*- coding: UTF-8 -*-
class Employee:
   '所有员工的基类'
   empCount = 0

   def __init__(self, name, salary):
      self.name = name
      self.salary = salary
      Employee.empCount += 1
   
   def displayCount(self):
     print "Total Employee %d" % Employee.empCount

   def displayEmployee(self):
      print "Name : ", self.name,  ", Salary: ", self.salary

所有的对象都有特定的操作;因为类不断进行细分。对象并不是数据的结构,所以他有很大的运行效率问题,但是是很自然的,功能强大且符合人类习惯。
面向过程全部依靠与操作,所以一般人秀不出来。

面向过程和计算机的执行结构密切相关。移动值并明确表示操作。而面向过程往往只是给与一个意图,而非明确算法,可以进行高质量代码的优化。

可以认为OOP和POP本质是正交的。没有高级的操作便没有面向对象编程,面向对象实际割舍了大部分的面向过程性质。这两者无法成为统一体,因为效率和高速的开发不可兼得。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值