Structure and Design of A Class
Structure and Design of A Class
5. firstprogram.display();
6. return 0;
7.}
•firstprogram is declared as an object of the class circle.
•A class is an actual representation of an ADT.
•It therefore provides implementation details for the
used data structure and operations. We play with the
ADT Integer and design our own class for it:
1.class Integer {
2.attributes:
3.int a;
4.methods:
5.setValue(int n)
6.addValue(Integer j)
7.};
•In this notation class {…} denotes the
definition of a class. Enclosed in the curly
brackets are two sections attributes: and
methods: which define the implementation of
the data structure and operations of the
corresponding ADT. Again we distinguish the
two levels with different terms:
Attributes which are elements of the data
structure at the ADT level.
Methods are the implementation of the
ADT operations.
•In above example, the data structure
consists of only one element: a signed
sequence of digits. The corresponding
attribute is an ordinary integer of a
programming language1. We only define
two methods setValue() and addValue()
representing the two operations set and
add.
•Definition
•A class is the implementation of an
abstract data type (ADT).
•It defines attributes and methods which
implement the data structure and
operations of the ADT, respectively.
•Instances of classes are called objects.
Consequently, classes define properties
and behaviour of sets of objects
Example