M/F 2:30-3:20   
in G01 Gates Hall

CS 1130: Transition to OO Programming

Spring 2016

Part 4. Programming Style Part 6. Reading and Writing Files

Module 2, Part 5

Advanced OO Concepts

The concepts of abstract classes and abstract methods solve two problems that arise in developing a system of classes and subclasses. The interface is used to define methods that a class that wants to "implement the interface" must define.


Contents

Abstract Classes and Methods

Reading: Gries/Gries, Sec. 4.7, pp. 163–164.
Read p. 4-5 of the ProgramLive CD and watch the lectures on that page.

Comments: Make a class abstract so that it cannot be instantiated (instances of it cannot be created). All you can do is make subclasses of it. Within an abstract class, make a method abstract so that it must be overridden in every subclass (that is not itself abstract).


2. Interfaces

Reading: Gries/Gries, Sec. 12.1–12.3, pp. 335–344.
Sec. 12.1 of Gries/Gries describes the interface and how it is used. The other two sections give important examples of interfaces in Java.
The lectures on pp. 12-1 and 12-2 of the ProgramLive CD explain the definition of an interface as well as how to implement it in other classes. Pages 12-3 and 12-4 then describe four important interfaces that are defined in the API package.

Comments: You need not study this material. It is presented because the interface is an important mechanism in Java, and it is used in describing and implementing "abstract data types". It will be used heavily in CS211.

An interface gives the syntax of some methods, and any class that "implements" the interfaces must define these methods. Interfaces provide a useful mechanism for signaling that a class will definitely implement certain methods.