Object-Oriented Design & Patterns

Cay S. Horstmann

Chapter 4

Interfaces and Polymorphism

Slide navigation: Forward with space bar, → arrow key, or PgDn. Backwards with ← or PgUp.

Chapter Topics

Displaying an Image

.

Displaying an Image

.

Displaying an Image

.

The Icon Interface Type

public interface Icon
{
   int getIconWidth();
   int getIconHeight();
   void paintIcon(Component c, Graphics g, int x, int y);
}

Interface Types

The Icon Interface Type and Implementing Classes

.

Polymorphism

Polymorphism

A Variable of Interface Type

.

Polymorphism

Benefits of Polymorphism

The Comparable Interface Type

The Comparable Interface Type

The Comparator interface type

The Comparator interface type

Lambda Expressions

Lambda Expression Syntax

Accessing Variables from the Enclosing Scope

Frames

Adding Components

.

User Interface Actions

User Interface Actions

User Interface Actions

Constructing Related Actions

 
    

Timers

.

Drawing Shapes

Drawing Rectangles and Ellipses

Drawing Ellipses

.

Drawing Line Segments

Relationship Between Shape Classes

.

Drawing Text

.

Filling Shapes

.

Defining a New Interface Type

.

CRC Card for the MoveableShape Interface Type

.

Defining a New Interface Type

Implementing the Animation

Implementing the Animation

Implementing the Animation

.