属性是抽象定义的一部分吗

属性是抽象定义的一部分吗

本文介绍了“不变"属性是抽象定义的一部分吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为我学习的一部分,我认为我发现的抽象定义的最佳答案(有意义)来自 stackoverflow:

As part of my learning i think the best answer(with meaning) for definition of abstraction that i found is from stackoverflow:

什么是抽象?

除此之外,

作为当前在线课程 cs61B 伯克利 2006 年秋季的一部分,我学习了与上述定义接近的 ADT 的以下类似定义,但添加了一个额外的词不变".我可以将这个词视为上述定义的推论吗?或者这个词是定义的一部分吗?

As part of current online course cs61B Fall 2006, Berkeley, i learnt the similar below definition of ADT close to above definition but added an extra word 'invariant'. Shall i consider this word as corollary to the above definition? or Is this word part of the definition?

一个 _Abstract_Data_Type_ (ADT) 是一个具有明确定义接口的类,但它的实现细节对其他类是严格隐藏的.这样,你可以在不危及依赖于它的程序的情况下改变一个类的实现.Date 类是一个 ADT.

An _Abstract_Data_Type_ (ADT) is a class that has a well-defined interface, but its implementation details are firmly hidden from other classes. That way, youcan change the implementation of a class without jeopardizing the programs that depend on it. The Date class is an ADT.

ADT 允许您强制执行不变量.

不变量是关于数据结构的事实,它始终为真(假设代码没有错误),无论外部类调用什么方法.例如,Date ADT 强制执行不变量,即 Date 对象始终表示有效日期.通过仅允许通过方法调用访问某些字段来强制执行不变量.

An invariant is a fact about a data structure that is always true (assuming the code is bug-free), no matter what methods are called by external classes.For example, the Date ADT enforces the invariant that a Date object always represents a valid date. An invariant is enforced by allowing access to certain fields only through method calls.

推荐答案

我最喜欢的抽象定义之一是 Robert C. Martin 的,来自 敏捷原则、模式和实践:

One of my favourite definitions of abstraction is Robert C. Martin's, from the book Agile Principles, Patterns, and Practices:

抽象是对不相关的剔除,对本质的放大.

基于该定义,抽象可以在许多不同的层次上采用多种形式:

Based on that definition, an abstraction can take many forms, on many different levels:

  • 它可以是一个完整的系统
  • 它可以是一个子系统
  • 它可以是消息格式的定义(类似于协议)
  • 它可以是一个函数(如在函数式编程中)
  • 它可以是一个抽象基类
  • 它可以是一个接口
  • 它可以是一个具体的类

面向对象软件构造中,Bertrand Meyer 将类描述为抽象数据类型.本书的想法是抽象数据类型的描述包括前置条件和后置条件.在 Eiffel(本书中使用的语言)中,这些被称为断言,但我们也将它们称为不变量.

In Object-Oriented Software Construction, Bertrand Meyer describes classes as Abstract Data Types. The idea in this book is that the description of an Abstract Data Type includes pre- and post-conditions. In Eiffel (the language used in the book), these are called assertions, but we also know them as invariants.

Meyer 对面向对象设计的看法包括不变量.在详细(类/对象/函数)级别上,我同意将不变量视为一种描述抽象的方式是有意义的.

Meyer's view on Object-Oriented Design includes invariants. On a detailed (class/object/function) level, I agree that it makes sense to view invariants as a way to describe an abstraction.

另一方面,如果您的抽象是对高级架构的描述,那么那些类型的不变量就没有意义.尽管如此,即使在高层次上,定义前置条件和后置条件通常也很有价值(例如系统 A 必须响应才能使系统 B 正常工作"),因此考虑不变量是有意义的与抽象的关系.

On the other hand, if your abstraction is a description of a high-level architecture, those kind of invariants doesn't make sense. Still, even at a high level, it would often be valuable to define pre- and post-condition (e.g. "System A must be responding in order for System B to work correctly"), so it does makes sense to think about invariants in relation to abstractions.

这篇关于“不变"属性是抽象定义的一部分吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 22:14