


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Data abstraction, a programming methodology that supports modifiability, extensibility, and re-usability through encapsulation. The concept of data abstraction and its implementation in modula-2 and ada using modules. Modules are collections of declarations, including types, variables, and procedures, that can be imported and exported to create encapsulated namespaces. The roles of modules, their interface and implementation, and management issues.
Typology: Papers
1 / 4
This page cannot be seen from the preview
Don't miss anything!



DEFINITION MODULE ComplexNumbers; TYPE COMPLEX: (* opaque type *) PROCEDURE Add (x, y: COMPLEX):COMPLEX; PROCEDURE Subtract (x, y: COMPLEX):COMPLEX; PROCEDURE Multiply (x, y: COMPLEX):COMPLEX; PROCEDURE Divide (x, y: COMPLEX):COMPLEX; PROCEDURE Negate (z: COMPLEX):COMPLEX; PROCEDURE MakeComplex(x, y: REAL): COMPLEX; END ComplexNumbers.
IMPLEMENTATION MODULE ComplexNumbers; FROM Storage IMPORT ALLOCATE; TYPE COMPLEX = POINTER TO ComplexRecord; ComplexRecord = RECORD re, im: REAL; END; PROCEDURE Add(x, y: COMPLEX):COMPLEX; VAR t: COMPLEX; BEGIN NEW(t); tˆ.re := xˆ.re + yˆ.re; tˆ.im := xˆ.im + yˆ.im; END Add ...
MODULE ComplexUser; FROM ComplexNumbers IMPORT COMPLEX, Add, MakeComplex; VAR x, y, z: COMPLEX; BEGIN x := MakeComplex(1.0, 2.0); y := MakeComplex(-1.0, 1.0); ... z := Add(x, y); END
x := ComplexNumbers.MakeComplex(1,0,2.0);
package ComplexNumbers is type COMPLEX is private; function Add(x, y: in COMPLEX) return COMPLEX; function Subtract(x, y: in COMPLEX) return COMPLEX; function Multiply(x, y: in COMPLEX) return COMPLEX; function Divide(x, y: in COMPLEX) return COMPLEX; function Negate(z: in COMPLEX) return COMPLEX; function MakeComplex(x, y: in FLOAT) return COMPLEX; private type COMPLEX is record re, im: FLOAT; end; end ComplexNumbers;
package body ComplexNumbers is
function Add(x, y: in COMPLEX) return COMPLEX is t: COMPLEX; begin t := new ComplexRecord; t.re := x.re + y.re; t.im := x.im + y.im; end Add; ... end ComplexNumbers
with ComplexNumbers; use ComplexNumbers; procedure ComplexUser is z, w: COMPLEX; ... begin z := MakeComplex(1.0, 1.0); ... w := Add(z, z); end ComplexUser;
Interface StackInterface { int MAXSTACKSIZE = 100; public char pop; public void push(char val); } class StackArray Implements StackInterface { private char elements[]; public char pop() { return elements[top]; } public void push(char elem) { ...} ... } class StackLinkedList Implements StackInterface { private CharLinkedList elementsList; public char pop() { ... } public void push(char elem) { ...} ... }
class Stack { public: char pop(); void push(char); private: int top; char elements[10]; };
class Stack { friend ostream& operator<<(ostream&, const Stack&); friend istream& operator>>(istream&, Stack&); ... };
Stack() { top = 0;} .. Stack X[100];
˜Stack();
Stack *x; ... x->˜Stack(); // does not deallocate space
Stack(const Stack &);
operator Stack::int() { ... } ... Stack x; int i = int(x);