Encapsulation: purposeful hiding of information,
thereby reducing the details to be remembered/communicated
Instantiation: create multiple instances of an
abstraction
State - Instance Variables
Instance - a representative
or example of a class
Instance Variable - the state, or data values,
maintained internal to a class
Record information about instance variables on the back
of the CRC card
- clients can see front of CRC card
- implementors can see on the back of the CRC card
|--------------------------------------------------------------|
|
Card  
;
|
| Maintain
and return suit and rank
|
| Return color
of face &n
bsp;
|
| Maintain
face-up or face-down status
|
| Draw card
on playing surface
|
| Erase
card on playing surface
|
|-------------------------------------------------------------|
|-------------------------------------------------------------|
|----------------------------------------------------------------|
| Card &nb
sp;
|
| suit( ) -
return suit value &nbs
p;
|
| rank(
) - return rank value
|
| color( ) - return color
value
|
| erase(x,y ) - erase card
image
|
| draw( x,y) - draw card image
|
| faceUp( ) , flip ( ) - test or
flip card
|
|---------------------------------------------------------------
|
Interface and implementation
Distinction between interface and implementation is manifest
in different ways:
Data sink or source : interface to data generator
or consumer, no data itself
example : input/output
stream objects - files, i/o devices
View or observer class: display objects graphically, not the object itself
// constructor
Card (int sv, int rv) { s= sv; r= rv; faceup = false;
}
// mutator
public void flip ( ) { faceup = ! faceup }
// accesors
public int rank ( ) { return r; }
public int suit ( ) { return s; }
public int color ( ) {
if (suit( ) = = heart || suit = = diamond )
return
red;
return
black; }
public boolean faceup ( ) { return faceup; }
// perform other actions
public void draw( Graphics g, int x,int y ) {
. . ./* omitted */. . .
// data fields
private boolean faceup;
private int r;
private int s;
};