A Relational Model

4.5.1 A Relational Model

As we recall from our discussion in Section 4.1, specifications have to have two key attributes, which are formality and abstraction. We can achieve formality by using a mathematical notation, which associates precise semantics to each statement. As for abstraction, we can achieve it by ensuring that the specifications describe the exter- nally observable attributes of candidate software products, but do not specify, dictate, or otherwise favor any specific design or implementation.

We consider the following description of a stack data type: A stack is a data type that is used to store items (through operation push()) and to remove them in reverse order (through operation pop()); operation top() returns the most recently stored item that has not been removed, operation size() returns the number of items stored and not removed, and operation empty() tells whether the stack has any items stored; operation init() reinitializes the stack to an initial situation, where it contains no elements. Imag- ine that we want to specify a stack without saying anything about how to implement it. How would we do it? Most data structure courses introduce stacks by showing a data

4.5 STATE-BASED SYSTEMS

structure made up of an array and an index into the array and by explaining how push and pop operations affect the array and its index; but such an approach violates the principle of abstraction since it specifies the stack by describing a possible implemen- tation thereof. An alternative could be to specify the stack by means of an abstract list, along with list operations, without specifying how the list is implemented. We argue that this too violates the principle of abstraction as it dictates a preferred implemen- tation; in fact, a stack does not necessarily require a list of elements, regardless of how the list is represented, as we show here.

• Consider that a stack that stores identical elements can be implemented by a sim- ple natural number, say n:

• init(): {n=0;} • push(a): {n=n+1;} // a is the only value that can be

//stacked

• pop(): {if (n>0) {n=n-1;}} • top():

{if (n>0) {return a;} else {return error;}} • size(): {return n;}

• empty(): {return (n==0);}

• Consider that a stack that stores two possible symbols (e.g., ‘{’ and ‘}’) can also

be implemented without any form of list, using a simple natural number, say n:

• init(): {n=1;}

//symbols onto 0 and 1. • pop(): {if (n>1) {n=n div 2;}}

• top(): {if (n==1) {return error;} else {return decode (n mod 2);}} // decode() is the inverse of code().

• size(): {return floor(log2(n));} • empty(): {return (n==1);}

• We can likewise implement a stack that stores any number (k) of symbols by using base-k numeration rather than base 2 (used earlier).

Hence, for the sake of abstraction, we resolve to specify the stack by describing its externally observable behavior, without making any assumption, regardless of how vague, about its internal structure. To this effect, we specify a stack by means of three parameters, which are as follows:

• An input space, say X, which includes all the operations that may be invoked on the stack. Hence,

X = init pop top size empty push × itemtype, where itemtype is the data type of the items we envision to store in the stack.

64 SOFTWARE SPECIFICATIONS

We distinguish, in set X, between inputs that affect the state of the stack (namely, AX = init, push, pop ) and inputs that merely report on it (namely,

VX = top, size, empty ). From the set of inputs X, we build the set of input histories, H, where an input history is a sequence of inputs; this is needed because the behavior of the stack is not determined solely by the current input but involves past inputs as well. ○ Hence, we introduce the set of input histories, H = X ∗ .

• An output space, say Y, which includes all the values returned by all the elements of VX. In the case of the stack, the output space is as follows: Y = itemtype

error

integer boolean,

which correspond, respectively, to inputs top, size, and empty. •

A relation from H to Y, which represents the pairs of the form (h, y), where h is an input history and y is an output that the specifier considers correct for h. We denote this relation by stack and we use the notation stack (h) to refer to the image of h by stack (if that image is unique) or to the set of images of h by stack (if h has more than one image). We present here some pairs of the form (h, y) for relation stack: ○ stack pop init push a init push a top = a.

○ stack pop init pop push a push b top top = b. ○ stack init pop push a pop push a pop push a size = 1. ○ stack pop push a pop init pop push a top push a top push a

pop empty = false. ○ stack init pop pop pop push a push b push c top push c push b

empty top = b. We can go on describing possible input histories and corresponding outputs. In

doing so, we are specifying how operations interact with each other but we are not prescribing how each operation behaves; this leaves maximum latitude to the designer, as mandated by the principle of abstraction.

It is clearly impractical to specify data types by listing elements of their relations; in the next section, we explore a closed-form representation for such relations.

Dokumen yang terkait

Analisis Komparasi Internet Financial Local Government Reporting Pada Website Resmi Kabupaten dan Kota di Jawa Timur The Comparison Analysis of Internet Financial Local Government Reporting on Official Website of Regency and City in East Java

19 819 7

ANTARA IDEALISME DAN KENYATAAN: KEBIJAKAN PENDIDIKAN TIONGHOA PERANAKAN DI SURABAYA PADA MASA PENDUDUKAN JEPANG TAHUN 1942-1945 Between Idealism and Reality: Education Policy of Chinese in Surabaya in the Japanese Era at 1942-1945)

1 29 9

Improving the Eighth Year Students' Tense Achievement and Active Participation by Giving Positive Reinforcement at SMPN 1 Silo in the 2013/2014 Academic Year

7 202 3

Improving the VIII-B Students' listening comprehension ability through note taking and partial dictation techniques at SMPN 3 Jember in the 2006/2007 Academic Year -

0 63 87

The Correlation between students vocabulary master and reading comprehension

16 145 49

Improping student's reading comprehension of descriptive text through textual teaching and learning (CTL)

8 140 133

The correlation between listening skill and pronunciation accuracy : a case study in the firt year of smk vocation higt school pupita bangsa ciputat school year 2005-2006

9 128 37

Perancangan Sistem Informasi Akuntansi Laporan Keuangan Arus Kas Pada PT. Tiki Jalur Nugraha Ekakurir Cabang Bandung Dengan Menggunakan Software Microsoft Visual Basic 6.0 Dan SQL Server 2000 Berbasis Client Server

32 174 203

Pengaruh Kualitas Software Aplikasi pengawasan kredit (C-M@X) Pt.PLN (PERSERO) Distribusi Jawa Barat Dan Banten (DJBB) Terhadap Produktivitas Kerja karyawan UPJ Bandung Utara

5 72 130

Transmission of Greek and Arabic Veteri

0 1 22