X 上的抽象

发布于 2024-09-05 07:07:30 字数 73 浏览 1 评论 0原文

很抱歉这个与英语相关的问题,但我只在 IT 背景下遇到过这个表达。对某事进行抽象是什么意思?例如对对象进行抽象或对类进行抽象。 谢谢

Sorry for this english related question but I only came across that expression in the context of IT. What does abstracting over something mean ? For example abstracting over objects or abstracting over classes.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独行侠 2024-09-12 07:07:31

这意味着将其作为参数提取到函数中。它在函数式编程中更有意义,但假设您有一个函数,它接受一个整数并将其加五,您可以将其设为一个变量,并有一个可对任意两个整数起作用的求和函数。

那个案子没那么有趣。现在,如果您将加法运算拉出来并使其成为一个参数,该怎么办?现在您有一个函数,它接受两个参数并应用调用第三个参数作为它们的函数。在这里,您已经从函数中抽象出了操作。

抱歉,这是一个很弱的解释,稍后有机会时我会修复它。有几个很好的例子是有道理的,我只需要运行 ATM 就可以了。

It means to pull it out for a function as an argument. It makes more sense in functional programming but imagine you have a function that takes an integer and adds five to it you could make that a variable and have a sum function that would work on any two integers.

That case is not so interesting. Now what if you pulled the addition operation up and made it an argument. Now you have a function that takes two arguments and applies calls the third as a function on them. Here you have abstracted the operation out of the function.

Sorry this is such a weak explanation, I will fix it later when I get a chance. It makes sence with a couple of nice examples, I just have to run ATM.

傻比既视感 2024-09-12 07:07:30

在这种情况下,“抽象”一词来自 lambda 演算,意思是“使某物成为参数”(值参数或类型参数)。该词更普遍地与其他类型的参数一起使用;例如,“通用编程”机制通常包括对类进行抽象的方法。

也许最简单的抽象对象和类的语言是 Smalltalk,其中一切(包括每个类)都是一个对象。 Smalltalk 与紧密基于 Smalltalk 的 Ruby 一样,具有“鸭子类型”,因此,例如,您可以通过编写仅使用所有集合类通用方法的 Smalltalk 代码来“抽象”任何集合类。您可以以类似的方式抽象集合对象。

In this context, the word "abstract" comes from the lambda calculus, where it means "to make something a parameter" (a value parameter or a type parameter). The word is used more generally with other kinds of parameters; for example, mechanisms for "generic programming" often include ways of abstracting over classes.

Probably the easiest language in which to abstract over objects and classes is Smalltalk, where everything (including every class) is an object. Smalltalk, like Ruby which is closely based on Smalltalk, has "duck typing", so for example you could "abstract over" any collection class by writing Smalltalk code that uses only methods common to all collection classes. You could abstract over collection objects in a similar way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文