什么是“契约”一个意思是 [英] What does "contract" of a class mean

查看:356
本文介绍了什么是“契约”一个意思是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 Java编程语言这本书。在解释覆盖方法的章节中,它说:

I am reading the book The Java Programming Language. In the chapter which explains overriding method, it says:


使覆盖方法(在子类中)不易访问比超级类更违反了超类的合同...

Making an override method (in subclass) less accessible than it was in super class would violate the contract of the superclass ...

整个文本是可以理解的。我唯一的问题是超类合同是什么? 契约 Java 类意味着什么?

The text as a whole is understandable. My only question is what is contract of the superclass? What does the contract mean for a Java class?

推荐答案

A在Java类中的契约类似于现实世界中的契约 - 在非技术术语中:

A contract in in a Java class is similar to a contract in the real world - In non-technical terms:

这是一个协议,该类将暴露某些方法,某些属性和某些行为。

It's an agreement that the class will expose certain methods, certain properties, and certain behaviors.

更多技术,来自这里 :(由我添加粗体)

More technical, from here: (bold added by me)


如果你使用的所有Java类都不是很好,包括你的
拥有,兑现了他们的承诺?事实上,如果你实际知道某个特定类承诺的是什么,那么这不是很好吗?如果您同意,请在[...]上阅读

Wouldn't it be nice if all Java classes that you use, including your own, lived up to their promises? In fact, wouldn't it be nice if you actually knew exactly what a given class promises? If you agree, read on [...]

按合同设计

设计通过合同(DBC)软件开发技术,通过保证系统的每个组件
符合其预期,确保
高质量软件。作为使用DBC的开发人员,您可以将
组件合同指定为组件接口的一部分。 合约
指定该组件对客户的期望以及客户可以预期的

The Design by Contract (DBC) software development technique ensures high-quality software by guaranteeing that every component of a system lives up to its expectations. As a developer using DBC, you specify component contracts as part of the component's interface. The contract specifies what that component expects of clients and what clients can expect of it.

这篇关于什么是“契约”一个意思是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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