Flylib.com

Books Software

 
 
 

8.5 A Useful Abstract Class That Is Not a Base Class?

 <  Free Open Study  >  

8.5 A Useful Abstract Class That Is Not a Base Class?

Recall in Chapter 5 that we discussed Heuristic 5.6, which states, "All abstract classes must be base classes in order to be useful." At that time, we observed that for all intents and purposes this was true, but we mentioned an anomalous case whose discussion we postponed. Consider a class composed of all class-specific data and methods . In our keyword implementation of class-specific data and behavior, this would amount to all static data and function members (a la C++). Such a class could be abstract, given that we would not define a constructor, yet the class would have some use in the system. This technically shows an abstract class from which no one inherits yet it is still useful. Why would anyone desire a class with no object-specific methods or data? I had never seen a need for such a class, but someone had mentioned this example in a design course long ago and I passed it along for the purists to ponder. Robert Martin, in the course of reviewing this book, provided a practical example for such a class wherein it is used to encapsulate and limit the scope for a collection of global data. This allows for better understandability of the application as well as the avoidance of namespace pollution (i.e., the cluttering of an application's global name space with duplicate names , causing link errors). I pass along his example for your review (see Figure 8.5).

Figure 8.5. Example of a useful abstract class that lacks derived classes.

graphics/08fig05.gif

 <  Free Open Study  >  
 <  Free Open Study  >  

Glossary

Class method

A method that is attached to a class as opposed to the objects of a class. Class methods cannot operate on object-specific data or invoke object-specific methods.



Class variable

A piece of class-specific data.



Metaclass

A class whose instances are classes.



Namespace pollution

The collision of names in the global name space of an executable file, often resulting in link errors.



Object data

The data of a class of which each object is to receive a unique copy.



Object method

A method that is attached to the objects of a class, that is, it requires an object of the associated class in order to execute.



Template

A C++ language mechanism that allows for the encapsulation of common code where the only distinction between the code modules is the name of a data or function member. Also called a generic or a parameterized class.



 <  Free Open Study  >  
 <  Free Open Study  >  

Heuristics Summary

Heuristic 8.1 Do not use global data or functions to perform bookkeeping information on the objects of a class. Class variables or methods should be used instead.

 <  Free Open Study  >  
 <  Free Open Study  >  

Chapter 9. Physical Object-Oriented Design

Section 9.1.   The Role of Logical and Physical Object-Oriented Design

Section 9.2.   The Construction of Object-Oriented Wrappers

Section 9.3.   Persistence in an Object-Oriented System

Section 9.4.   Memory Management Issues in an Object-Oriented Application

Section 9.5.   Minimal Public Interfaces for Reusable Components

Section 9.6.   Implementing Safe Shallow Copies

Section 9.7.   Concurrent Object-Oriented Programming

Section 9.8.   Implementing Object-Oriented Designs in Nonobject-Oriented Languages

Glossary

Summary of Heuristics

 <  Free Open Study  >