07 ADT - Encapsulation
07 ADT - Encapsulation
Constructs
sortInt(list, listLength)
Program units that use a specific abstract data type are called
clients of that type
situations arise in which clients need to access the data
members. The common solution is to provide accessor
methods; getters and setters
allow clients indirect access to the so called hidden data; a
better solution than simply making the data public, which
would provide direct access
Constructors:
• Functions to initialize the data members — they don’t
create objects
• May also allocate storage if part of the object is
heap-dynamic
• Can include parameters to provide parameterization of the
objects
• Implicitly called when an instance is created — but can be
called explicitly
• Name is the same as the class name
Destructors:
• Clean up after an instance is destroyed — usually just to
reclaim heap storage
• Implicitly called when the object’s lifetime ends, or explicitly
called
• Name is the class name, preceded by a tilde ( )
CSC 3112: Principles of Programming Languages 18/26
Parameterized ADTs
class Stack {
...
Stack (int size) {
stk_ptr = new int [size];
max_len = size - 1;
top = -1;
};
...
}
Stack stk(100);