什么是对象和OOP一个结构之间的区别? [英] What's the difference between an object and a struct in OOP?

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

问题描述


  • 有什么区别和对象从结构?

  • 在当前以及为什么我们使用一个对象,而不是一个结构?

  • 如何将数组从两者相差,当我们为什么要使用一个数组,而不是一个对象或一个结构?

我要得到一个什么样的每个适用于一个想法。

I would like to get an idea of what each is intended for.

推荐答案

显然,你可以根据自己的编程风格模糊的区别,但一般一个结构是结构化的数据块。一个目标是能够执行某种任务的主权实体。在大多数系统中,对象有一定的状态,因此有他们背后的一些结构化的数据。然而,一个精心设计类的主要功能之一是数据隐藏 - 一类究竟是如何做到无论它是不透明和不相关

Obviously you can blur the distinctions according to your programming style, but generally a struct is a structured piece of data. An object is a sovereign entity that can perform some sort of task. In most systems, objects have some state and as a result have some structured data behind them. However, one of the primary functions of a well-designed class is data hiding — exactly how a class achieves whatever it does is opaque and irrelevant.

由于类可用于重新present经典的数据结构,例如数组,哈希映射,树木等,你经常看到他们作为结构化数据块中的个别事​​物。

Since classes can be used to represent classic data structures such as arrays, hash maps, trees, etc, you often see them as the individual things within a block of structured data.

数组是非结构化数据块。在许多编程语言中,在数组中每一个独立的东西必须是相同的基本型(如每个人都为整数,每一个是一个字符串,或类似),但是,是不是在许多其他语言如此。

An array is a block of unstructured data. In many programming languages, every separate thing in an array must be of the same basic type (such as every one being an integer number, every one being a string, or similar) but that isn't true in many other languages.

作为准则:


  • 使用数组作为把一大群的事情,没有其他内在结构或层次的地方,如一月所有收据或我的一切在丹麦购买

  • 使用结构化数据到数据的多个离散位复合成一个单独的块,比如你可能要一个x位置和y位置来描述一个结合点

  • 使用对象那里有这么认为或行为本身
  • 一个特定的演员或东西
  • use an array as a place to put a large group of things with no other inherent structure or hierarchy, such as "all receipts from January" or "everything I bought in Denmark"
  • use structured data to compound several discrete bits of data into a single block, such as you might want to combine an x position and a y position to describe a point
  • use an object where there's a particular actor or thing that thinks or acts for itself

对象的隐目的因此直接与在其上它们可以操作和所有捆绑在一起,使得该系统的任何其他部分能够干扰数据的任务相关联。服从适当的面向对象的设计原则,可能需要纪律在第一,但最终将大规模提高你的code结构,因此您的解决更大的项目,并与他人合作的能力。

The implicit purpose of an object is therefore directly to associate tasks with the data on which they can operate and to bundle that all together so that no other part of the system can interfere. Obeying proper object-oriented design principles may require discipline at first but will ultimately massively improve your code structure and hence your ability to tackle larger projects and to work with others.

这篇关于什么是对象和OOP一个结构之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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