Designing Specification

Functions & Methods in programming languages

Methods can be individually developed , tested and reused.

User of method does not need to know how the functions work.

A complete method:

specification+implementation

Specificatioon:Programming for communication

About "final"

declaring a variable final is a form of documentaion, a claim that the variable will never change after its initial assignment.

Why we nned to write specification?

  1. Remember them.
  2. Other people can read or change our programs only if they know them.
  3. different programmers on a team may have different specificaitons in mind.

Keep in mind:

  1. Communicating with the computer 
  2. Communicating with other people: make the program easy to understand

Specification acts as a contract :

  • the implementer is responsible for meeting the contract, and a client that uses the method can rely on the contract.
  • Specifications place demands on both parties: when the specification has a precondition, the client has responsibilities too.

Specification acts as a firewall between client and implementor

 Behavior equivalence

This part is easy to understand.

Precondition & postcondition

If the precondition holds for the invoking state, the method is obliged to obey the postcondition by returning appropriate values.

Translation:如果前提条件对调用的状态成立,方法就有义务遵守后置条件,返回适当的值。

If the precondition does not hold when the method is called , the implementation is not bound by the postcondition, which means it is free to do anything.

Stronger specification or waker?

A specification S2 is stronger than or equal to a specification S1 if

  • S2 ’s precondition is weaker than or equal to S1 ’s 
  • S2 ’s postcondition is stronger than or equal to S1 ’s, for the states that satisfy S1 ’s precondition.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值