2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > 过程式编程 vs 面向对象编程

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

时间:2024-04-12 00:54:59

相关推荐

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

过程式程序设计(英语: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 alsoimperativelanguages, because they make explicit references to the state of the execution environment. This could be anything fromvariables(which may correspond toprocessor registers) to something like the position of the "turtle" in theLogo programming language. Often, the terms "procedural programming" and "imperative programming" are used synonymously. However, procedural programming relies heavily onblocksandscope, 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 asif,while, andfor, to implementcontrol flow, whereasnon-structuredimperative languages usegotostatements andbranch tablesfor the same purpose.

The focus of procedural programming is to break down a programming task into a collection ofvariables,data structures, andsubroutines, whereas inobject-oriented programmingit 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.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。