Object-Oriented Programming

Handlers

Michael L. Collard, Ph.D.

Department of Computer Science, The University of Akron

Single Template Method

  • ConcreteClass has to subclass entire AbstractClass, including AbstractClass dependencies

  • For each abstract method, ConcreteClass must provide a definition

Multiple Template Methods

Another Issue

Goal

  • Separate primitive operations for a particular purpose from rest of class interface allows for decoupling of rest of class

  • Subclass the set of primitive operations, instead of the entire class

  • Reduces coupling, and have multiple template methods

Solution

Solution: Class Structure

Solution: main()

Solution: Method Definitions

Solution: Output

Compare

Multiple Handlers

Advantages

  • Replaces subclassing large, complex class with subclassing a cohesive interface

  • Allows multiple types of handlers, which the design can mix in new ways

  • Allows standard handlers to be created and shared

  • Easier to test, as can test individual handlers