ADT and OOP (2) Design specification (designing specification)

Source: Internet
Author: User
Tags variable scope

Directory

1. Functions/methods in the programming language (Function/method in programming language)

2. Communication Program Design specification (specification:programming for communication)

* Why need specification

* Behavioral Equivalence

* Standard structure: prerequisites and post conditions

3. Design specification (designing specifications)

* Classification Specifications

* Graphic Description

* Quality of specifications

Purpose of this lecture

1. Understand the prerequisites and post conditions in the method specification, and can write the correct specification

2. What are pre-requisites and post-conditions? What are their implications for the implementation and client approach?

3. Understand uncertain specifications and be able to identify and assess uncertainties

4. Understanding of declarative and operational specifications to write declarative specifications

5. Can compare the strength of the specification

6. Ability to write coherent and useful normative forces

1. Functions/methods in the programming language

(Function/method in programming language)

Variable scope

Main x = 5
Printsquare x = 5
Printsquare x =//x value has not been passed back to the main function
Main x = 5

Methods:building Blocks (Building blocks)

1. Large procedures are constructed in small ways.

2. Methods can be developed, tested and reused separately.

3. The user of the method does not need to know how it works---this is called "abstraction"

Example: Calculation of Hail sequence method

2. Specification: Communication programming

(Specification:programming for communication)

1. Programmatic documentation

Hacking vs. Engineering ( Hacker vs Engineering)

Hacker faction: Bold, Optimist

Cons: Write large amounts of code (with confidence 233) before testing, regardless of error

Cons: All the details in the mind, do not make comments ...

Cons: Self-thinking bugs are easy to find and easily solved

Engineering School: Cautious, pessimistic

Pros: Write a little bit of testing

Pros: Make good notes

Pros: Static checking helps to avoid stupid mistakes

2. Specification and contract (specification andcontract)

specification (or contract) Specifications (or called contract)

1. The specification is team work key . It is impossible to assign a task to a method that implements no specification .

2. The specification is the contract: the person responsible for the implementation. In order to meet the contract, customers using this method can rely on the contract.

2.1 State method and the responsibility of the caller

2.2 Definition of what is right for implementation

3. Like a real legal contract, the specification requires both parties. Parties: When a specification has a prerequisite, the client has the responsibility as well.

Why norm-setting

Realistic Requirements:

Many program bugs are due to different habits of the program Ape co-operation is not discussed, so it is necessary to establish a uniform norm

Advantages:

1. Accurate specifications to determine the wrong responsibility and location

2. The specification is beneficial to the customer because they save the task of reading the code.

Specification (Contract)

1. Norms are good for implementers a method because they give the implementers the freedom to change the implementation without telling the customer.

2. Specifications can write code more quickly (through restrictions on input, omit some time-consuming inspection work, improve efficiency)

3. The contract is a firewall between the customer and the person who implements it

3.1 It masks the details of the client from the work unit

3.2 It blocks the details of the implementation from the work unit

3.3 Allow Unit code and client code to change independently as long as the respect specification is changed

4. Agreement between the object and its users

4.1 Method signature (type specification)

4.2 Functionality and correctness of expectations

4.3 Performance expectations

5. How to do it, not how to do it

Interface (API) instead of implementing the

3. Behavioral equivalence (behavioral equivalence) Determining the behavior equivalence question is whether we can replace an implementation method with an implementation method.

These methods not only have different code, they actually have different behaviors as well. But these two methods behave the same way.

4. Prerequisites and post-conditions (pre-condition and post-condition)

Canonical structure

The specification of a method consists of several clauses:

Prerequisites, indicated by the keyword requirements

Post conditions, indicated by the keyword influence

Exceptions, what if the premises violate

The prerequisite is the obligation to the customer. This is a state in which the method is called.

The post-condition is the obligation to the performer. Method. If the condition of the calling state is persisted, then the method is obliged to obey the post-condition, passing the appropriate return value, throwing the specified exception, modifying or not modifying the object, and so on.

public class Test1 {
public static void Printsquare (int x) {
System.out.println ("Printsquare x =" + x);
x = x * x;
System.out.println ("Printsquare x =" + x);
}
public static void Main (string[] arguments) {
int x = 5;
System.out.println ("main x =" + x);
Printsquare (x);
System.out.println ("main x =" + x);
}
}

ADT and OOP (2) Design specification (designing specification)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.