什么是抽象?
我在流程中看到了抽象。 我在数据中看到了抽象。
我发现抽象正在失去不重要的细节。
我认为抽象是给一组元素一个名称并将它们视为一个单元。 (但我不知道为什么这被认为是抽象。所以,我需要澄清这一点)
我知道抽象也有层次,虽然名字暗示了一些东西,但我没有一个实际的例子,并且我想不出具体的一个,我对抽象的定义感到困惑。
有人可以写一篇综合性的文章吗?刮掉那个。有人能给个全面的答案吗?
编辑:- 谢谢您的回答。 然而,我一直在寻找一个普遍的答案。 例如,我正在阅读一篇文章,其中过程被视为抽象。 然而,这里的答案是关于 C# 和 Java 中的抽象类(到目前为止)。 再次感谢您。
I see abstraction in processes.
I see abstraction in data.
I see that abstraction is losing the unimportant details.
I see that abstraction is giving a group of elements a name and treating them as one unit. (But I don't know why that is considered abstraction. So, please I need clarification on this particular point)
I know there are also levels of abstraction, and although the name implies something, I don't have a practical example, and I can't think of a specific one I'm confused about the definition of abstraction.
Can somebody write a comprehensive article? Scratch that. Can somebody give a comprehensive answer?
EDIT:-
Thank you for your answers.
However, I was looking for a generalized answer.
For example, I'm reading an article in which procedures are considered abstractions.
However, here the answers are about abstract classes in C# and Java, (until now.)
Thank you again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
抽象是隐藏特定实现的细节并在实现之间共享公共细节。示例是 java.util.List、java.util.ArrayList 和 java.util.Map。 List是父级(抽象),ArrayList和Map是具体实现。
每当您在不同类之间共享代码时,您都需要执行此操作,这样就不会重复编写不好的代码。
抽象在代码重用、动态行为和标准化方面非常有用。例如,您正在使用一个方法,它接受一个 List,因此要使用此方法,您可以发送以 list 作为其父级的任何对象。现在,在该方法内部,根据传递对象的类型,可能有不同的实现,因此您可以在运行时实现动态行为。当您设计框架时,这是非常有用的技术。
Abstraction is hiding details of specific implementations and share common details among implementations. Example is java.util.List, java.util.ArrayList and java.util.Map. List is the parent (the abstraction), ArrayList and Map are specific implementation.
You want to do this whenever you have shared code between different classes, so that you don't repeat your code which is bad.
Abstraction is very useful in code reuse, dynamic behavior and standardization. For example, there is a method that you are using and it accepts a List, so to use this method, you can send any object that has list as its parent. Now inside this method, there could be different implementations depending on what is the type of the passed object, so you can achieve a dynamic behavior at run-time. This is very useful technique when you design a framework.
我不确定你是否应该推荐书籍,如果是的话请告诉我,我会删除我的帖子,但我喜欢 Troelsen 的 Pro C#。抽象就像接口,但接口不允许您定义构造函数。这是为了概括。就像我有一个网格,我想在其中显示一些用户字段。这些字段可以是文本、枚举、单值、多值。我使用抽象字符串属性 DispValue 构建了一个抽象类 FieldDef。然后各种字段类型继承自FieldDef。在网格中我有简单的字符串要显示。然后,当用户更新字段时,会公开特定于字段类型的属性和方法。另一个例子是所有哺乳动物都有共同的属性,但是当你深入研究时,你会暴露更多的属性,但是所有哺乳动物都有一个通用的视图(界面),并且通过从哺乳动物继承,有一种方法可以搜索和显示所有哺乳动物共有的属性。
I am not sure if you are supposed to recommend books and if so let me know and I will delete my post but I like Pro C# by Troelsen. Abstraction is like an Interfaces but Interfaces do not allow you to define constructor(s). It is for generalizing. Like I have a grid I want to display some user fields in. The fields can be text, enumeration, single-value, multi-value. I built an abstract class FieldDef with an abstract string property DispValue. Then the various field type inherit from FieldDef. In the grid I have simple string to display. Then when the user updates a field properties and methods specific to the field type are exposed. The other example is all mammals have common proprieties but as you drill down you expose more properties but there is a single generalized view (interface) for all mammals and by inheriting from mammals there is a way to search across and display properties common to all mammals.
抽象是隐藏实现的技术。从本质上讲,这个答案没有更多内容。抽象的大部分意义来自于它的使用方式和原因。
它用于以下场景
Abstraction is the technique of hiding implementation. At it's core there's not much more to that answer. The bulk of meaning to abstraction come from how and why it is used.
It is used for the following scenarios
很简单,抽象是限制依赖性的艺术。你依赖的越少,你就越抽象。例如,如果您编写 DirectX 渲染器,那么您就可以从所运行的显卡供应商和型号中抽象出来。如果您编写另一层,则可以与正在运行的操作系统隔离。
Quite simply, abstraction is the art of limiting your dependencies. The less you depend on, the more abstract you are. For example, if you write a DirectX renderer, then you're abstracted from what graphics card vendor and model you're running on. If you write another layer, you can be insulated from what OS you're running on.