Object Interaction

Programming Paradigms


Abstraction
The ability to ignore details of parts to focus attention on a higher level of a problem
The process of dividing a whole into well-defined parts, which can be built and examined separately, and which interact in well-defined ways

A class can have within it other classes

public class NumberDisplay
{
    private int limit;
    private int value;

}
public class ClockDisplay
{
private NumberDisplay hours;
private NumberDisplay minutes;
}

The variables in NumberDisplay are primitive types

The variables in ClockDisplay are object types

Objects creating objects

Formal parameter:

public NumberDisplay(int rollOverLimit);

Actual Parameter:

hours = new NumberDisplay(24);

Method calling

public void timeTick()
{
    minutes.increment();
    if(minutes.getValue() == 0) {
        // it just rolled over!
        hours.increment();
    }
    updateDisplay();
}

Internal Methods

/**
* Update the internal string that
* represents the display.
*/
private void updateDisplay()
{
    displayString =
    hours.getDisplayValue() + ":" +
    minutes.getDisplayValue();
}

Method calls

Internal method calls

updateDisplay;
private void updateDisplay()

External method calls

minutes.increment()