110 likes | 195 Views
Advanced Object Oriented Programming – Abstract classes and Interfaces. Chapter 27. Purpose: to simplify the design of medium to large sized programs. Advanced OOD concern with the identification of class structures and inheritance. Chapter facilities:.
E N D
Advanced Object Oriented Programming – Abstract classes and Interfaces Chapter 27
Purpose: to simplify the design of medium to large sized programs • Advanced OOD concern with the identification of class structures and inheritance
Chapter facilities: • Interfaces: “neatest” way for programs to deal with events • Abstract classes
Abstract classes – set up a class to be reused • Example program “Rectangle” See Author’s web site. Rectangle” extends “Shape” which is an abstract class • Declaring a class abstract forces programmer who uses it (via inheritance,) to provide missing methods – which “enforces” a particular design
Interfaces • Used in “Balloon” • Public interface Balloon { … • Note NO class • An interface describes only the services provided by the class • public class Spheroid implements Balloon …
Compiler checks to see if it complies with the interface declaration • Examples: Programs that use Buttons implement ActionListeners and Scrollbars AdjustmentListeners
Interface can be used to describe classes in a program • Inheritance structure “Is a” relationship • Can Not describe: • Implementations of methods • Classes which use other classes (“has a”) relationship
Multiple Inheritance • Some languages (C++) not Java • Java allows multiple implementations • Example programs: “Entertainment” and program “TV” which extends “Entertainment”
Interfaces versus abstract classes • 1. Abstract classes can provide implementation of one or more methods • 2. Can implement more than one interface but only extend (inherit) from one abstract class • 3. An interface is something that is used at compile time to perform checking • 4. Abstract class implies it’s methods will be fleshed out by the class that extends it
Designing multithreaded programs • 1. Use methods described in chapter 21 • 2. Analyze applications to see activities that need to be carried out in parallel • 3. Identify those objects that need to be threads • 4. Identify the nature of the interaction between threads (independent, mutual, exclusion, producer-consumer)
Other approaches: • Information systems: examples • Airline ticket reservation system • Real time systems • Fly by wire • Knowledge based systems • AI • Parallel or concurrent systems • Any computer systems that can carry on two or more tasks simultaneously • Mathematical “complex” processing • Games especially those with good graphics