面向对象编程和过程编程有什么区别? [英] What is the difference between object oriented programming and procedural programming?

查看:62
本文介绍了面向对象编程和过程编程有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,过程编程使用过程和函数或子例程.它提供了有关如何操作的分步说明.虽然另一方面面向对象我并不完全确定.我所看到的只是它使用对象"并且几乎​​相同?有人可以澄清和解释对象到底是什么吗?

From what I can gather procedural programming uses procedures and functions or sub routines. It gives a step by step instruction on what to do. Though object oriented on the other hand im not entirely sure. All I have seen is that it uses "objects" and is pretty much the same? Could someone clarify and explain what exactly an object is?

推荐答案

将所有编程视为管理两个基本概念之间的关系:
状态行为.状态是程序的数据.行为就是逻辑.

Think of all programming as managing the relationship between two fundamental concepts:
state and behavior. State is the data of your program. Behavior is the logic.

过程式编程基于分别实现这两个概念.状态保存在数据结构中.行为保存在函数(也称为过程或子例程)中.因此,过程应用程序将数据结构传递给函数以产生一些输出.

Procedural Programming is based on implementing these two concepts separately. State is held in data structures. Behavior is held in functions (also known as procedures or subroutines). A procedural application therefore passes data structures into functions to produce some output.

面向对象编程是基于将这两个概念结合起来实现的.状态和行为合并为一个新概念:对象.因此,OO 应用程序可以通过调用对象产生一些输出,而无需传递数据结构.

Object-Oriented Programming is based on implementing these two concepts together. State and Behavior are combined into one new concept: an Object. An OO application can therefore produce some output by calling an Object, without needing to pass data structures.

OO 的优势包括潜在的信息隐藏:如果调用者不需要传递任何数据结构,那么调用者就不需要知道任何数据结构,因此可以与数据格式完全解耦.

Advantages of OO include the potential for information hiding: if a caller needn't pass any data structure, then the caller needn't be aware of any data structure, and can therefore be completely decoupled from the data format.

过程逻辑和对象逻辑之间的一个根本区别在于处理选择的方式.过程使用分支逻辑处理选择:熟悉的 if/else 语法.对象更喜欢使用多态来处理选择.

One fundamental difference between the logic of procedures and the logic of objects is in the way selection is handled. Procedures handle selection using branching logic: the familiar if/else syntax. Objects prefer to handle selection using polymorphism.

Procedural 和 OO 之间也有相似之处.两者都代表了命令式编程风格,这意味着它们通过改变状态(无论是在数据结构内还是在对象内)进行操作,并提供有关如何计算输出的分步说明.命令式编程就像写菜谱.

There are similarities between Procedural and OO as well. Both represent an imperative style of programming, meaning they operate by mutating their state (whether inside a data structure or an object) and providing step-by-step instructions on how to compute output. Imperative programming is like writing a recipe.

最后请注意,这些是理想主义或纯粹"的定义.在现实世界中,范式融合在一起.您很少(如果有的话)会看到纯 OO 应用程序.来自多个范式的特征将被结合起来,无论好坏.

Finally note that these are idealistic or "pure" definitions. In the real world, paradigms merge. You will rarely, if ever, see a pure OO application. Features from multiple paradigms will be combined, for better or worse.

这篇关于面向对象编程和过程编程有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆