Java 212: - PowerPoint PPT Presentation

About This Presentation
Title:

Java 212:

Description:

Title: Chapter 11 Author: Course Technology Last modified by: Yosef Mendelsohn Created Date: 11/15/2002 7:59:11 AM Document presentation format: On-screen Show (4:3) – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 7
Provided by: Course396
Category:

less

Transcript and Presenter's Notes

Title: Java 212:


1
  • Java 212
  • Interfaces
  • Intro to UML Diagrams

2
UML Class Diagram class Rectangle
  • /- refers to visibility
  • Color coding is not part of the UML diagram

3
Interfaces
  • Definition A class that contains only abstract
    methods and/or named constants
  • Abstract methods are methods that have no body
  • The body for those methods should be written
    inside any class that implements the interface
  • Typically used as a software design parameter
    during the design phase of an application.
  • Also sometimes used as a workaround on Javas
    limitation of not allowing multiple inheritance
  • Java allows classes to implement more than one
    interface
  • eg If you want a class to respond to different
    kinds of events (ActionEvent, WindowEvent,
    MouseEvent, etc), you can have a class implement
    all of these interfaces.

4
public interface Animal public void
speak() public void eat() public class Dog
implements Animal public void
speak() System.out.println("Woof") publ
ic void eat() //code to display bone,
kibbles public class Whale implements
Animal public void speak() System.out.prin
tln("Squeak") public void eat() //code
to display little fish, plankton, etc
An Interface with two implemented classes
5
Interfaces
In our discussion of GUIs, we discussed the use
of inner (nested) classes to handle events. In
these cases, we implemented the interface by
creating a whole new inner class. However, we
could just as easily declared an outer class as
implementing the interface. public class
RectangleCalculator implements ActionListener
or even public class
RectangleCalculator implements ActionListener,
WindowListener, MouseListener //declares that
this class implements three interfaces
6
Two Interface Definitions
public interface WindowListener public void
windowOpened(WindowEvent e) public void
windowClosing(WindowEvent e) public void
windowClosed(WindowEvent e) public void
windowIconified(WindowEvent e) public void
windowDeiconified(WindowEvent e) public void
windowActivated(WindowEvent e) public void
windowDeactivated(WindowEvent e) public
interface ActionListener public void
actionPerformed(ActionEvent e)
Write a Comment
User Comments (0)
About PowerShow.com