找到一个完整的contract解释,不过还是有点不明白 Object-oriented programming strictly separates the notion of what is to be done from how it is done. "What" is described as a set of methods (and sometimes publicly available data) and their associated semantics. This combinationmethods, data, and semanticsis often described as a contract between the designer of the class and the programmer who uses it because it says what happens when certain methods are invoked on an object. This contract defines a type such that all objects that are instances of that type are known to honor that contract.A common assumption is that the methods declared in a class are its entire contract. The semantics of those operations are also part of the contract, even though they may be described only in documentation. Two methods may have the same name and parameters and throw the same exceptions, but they are not equivalent if they have different semantics. For example, not every method called print can be assumed to print a copy of the object. Someone might define a print method with the semantics "process interval" or "prioritize nonterminals"not that we'd recommend this. The contract of the method, both signature and semantics together, defines what it means.
constract 合同通常用constructor 说是 构造器,构造函数
对于 用它的类 是 在堆上创建对象
Object-oriented programming strictly separates the notion of what is to be done from how it is done. "What" is described as a set of methods (and sometimes publicly available data) and their associated semantics. This combinationmethods, data, and semanticsis often described as a contract between the designer of the class and the programmer who uses it because it says what happens when certain methods are invoked on an object. This contract defines a type such that all objects that are instances of that type are known to honor that contract.A common assumption is that the methods declared in a class are its entire contract. The semantics of those operations are also part of the contract, even though they may be described only in documentation. Two methods may have the same name and parameters and throw the same exceptions, but they are not equivalent if they have different semantics. For example, not every method called print can be assumed to print a copy of the object. Someone might define a print method with the semantics "process interval" or "prioritize nonterminals"not that we'd recommend this. The contract of the method, both signature and semantics together, defines what it means.
双方或多方当事人(自然人或法人)关于建立、变更 、消灭民事法律关系的协议。此类合同是产生债的一种最为普遍和重要的根据,故又称债权合同。《中华人民共和国经济合同法》所规定的经济合同,属于债权合同的范围。合同有时也泛指发生一定权利、义务的协议。又称契约。如买卖合同、师徒合同、劳动合同以及工厂与车间订立的承包合同等。
看了半天还是合同~~呵,不好意思···不过要流个东西的,嘿嘿····http://bbs.tsp2c.cn/?fromuid=136 希望兄弟们能体谅下小弟哦~~
面向对象的程序设计严格区分做什么和怎么做的概念。“做什么”被描述为一个方法集(有时还指公用数据)及其关联的语义。这种组合(方法,数据和语义)实际上是类的设计者和使用类的程序员之间的一种约定(contract),因为它说明了当调用对象上的某个方法时会发生什么。这个约定定义了一个类型,该类型的所有实例对象都被认为是遵从该约定的。
通常假设类中声明的方法是它的全部约定。但操作的语义也是约定的一部分,即使它们仅在文档中介绍。两个方法可以具有相同的名字和参数,抛出相同的异常,但是如果语义不同,它们仍然是不一样的。例如,并不是所有称为print的方法都要打印出一份该对象,有人可能希望它的语义是处理间距或区分非终结符优先次序。方法的约定,包括签名和语义,决定了他的含义。