分享

过程式编程 vs 面向对象编程

 培根阅读 2017-07-16

过程式程序设计(英语:Procedural programming),又称过程式编程、过程化编程,一种编程范型,有时会被视为是命令式编程的同义语。派生自结构化编程(Structured programming),主要采取程序调用(procedure call)或函数调用(function call)的方式来进行流程控制。流程则由包涵一系列运算步骤的程序(Procedures),例程(routines),子程序(subroutines), 方法(methods),或函数(functions)来控制。在程序运行的任何一个时间点,都可以调用某个特定的程序。任何一个特定的程序,也能被任意一个程序或是它自己本身调用。著名的例子有Linux内核,git,以及Apache HTTP Server等。


面向对象程序设计(英语:Object-oriented programming,缩写:OOP)是种具有对象概念的程序编程范型,同时也是一种程序开发的抽象方针。它可能包含数据、属性、代码与方法。对象则指的是类的实例。它将对象作为程序的基本单元,将程序和数据封装其中,以提高软件的重用性、灵活性和扩展性,对象里的程序可以访问及经常修改对象相关连的数据。在面向对象程序编程里,计算机程序会被设计成彼此相关的对象。重要的面向对象编程语言包含Common Lisp、Python、C++、Objective-C、Smalltalk、Delphi、Java、Swift、C#、Perl、Ruby 与 PHP等。


Procedural programming languages are also imperative languages, because they make explicit references to the state of the execution environment. This could be anything from variables (which may correspond to processor registers) to something like the position of the 'turtle' in the Logo programming language.  Often, the terms 'procedural programming' and 'imperative programming' are used synonymously. However, procedural programming relies heavily on blocks and scope, whereas imperative programming as a whole may or may not have such features. As such, procedural languages generally use reserved words that act on blocks, such as ifwhile, and for, to implement control flow, whereas non-structured imperative languages use goto statements and branch tables for the same purpose.


The focus of procedural programming is to break down a programming task into a collection of variables, data structures, and subroutines, whereas in object-oriented programming it is to break down a programming task into objects that expose behavior (methods) and data (members or attributes) using interfaces. The most important distinction is that while procedural programming uses procedures to operate on data structures, object-oriented programming bundles the two together, so an 'object', which is an instance of a class, operates on its 'own' data structure.




    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多