java类中的规范和实现?

时间:2012-09-06 03:10:25

标签: java class inheritance

我无法理解这些术语的含义,如果有人能向我解释,我会很感激。

我已经有3个课程叫做: 形状 长方形 圆

然后我创建一个名为Triangle的类

a)当他们说为Rectangle ADT创建一个Triangle ADT类似规范的规范时,它是什么意思(我已经上过这个类)

b)实现Triangle类

2 个答案:

答案 0 :(得分:0)

“创建三角形ADT的规范”意味着定义您需要定义三角形的数据(三个笛卡尔坐标是最直接的,但它可以是单个点,3个角度和一个边长度,或其他)。

“实现类Triangle”意味着编写一个implements Shape的java类,但其内部实现是从步骤1开始定义的java中的表示。

答案 1 :(得分:0)

ADT:独立于实现的数据描述,指定数据的内容,结构和合法操作。

有一个ADT
Name:
Description of the data structure:
Operations:

Construction operations:
Initial values;
Initialization processes;
    For each operation:
    Name of the operation;

Input: External data that comes from the user of this data (client)

Preconditions: Necesssary state of the system before executing this operation;

Process: Actions performed by the data

Output: Data that is output to the client

Post Conditions: State of the system after executing this operation

示例:

ADT circle
Data: r³ 0 (radius);
Operations

    Costructor:

        Initial values:radius of circle;
        Process: Assign initial value of r;

    Area:

        Input: none;
        Preconditions: none;
        Process: A ¬ p *r*r Output: A
        Postcondition: none

    Circumference:

        Input: None;
        Preconditions: none;
        Process: C ¬ 2*p *r
        Output: C
        Postconditions: none;

End ADT circle;