next up previous contents index
Next: Naming Conventions Up: Creating a New Class Previous: Creating a New Class

Design and Implementation

Designing and implementing a class are two different steps. First you have to decide what the instances of the new class should look like, that is what data should be stored in them, and which methods, that is operations on the data, are needed.

Then you have to find a suitable superclass for the new class, this superclass will be extended by adding the instance variables of the new class to its structure and by implementing new methods.

The new class inherits all the functionality of its superclass, because all existing superclass methods can be called on the new class, too. A superclass method may be overwritten by implementing a method with the same name for the new class, this method of course may call the superclass method to extend its functionality for the new class instead of replacing it. This inheritance ensures that you have to write the least amount of code necessary to make the new class work, and it will lead to more stable programs because you can rely on the already working superclass code. For these reasons choosing a superclass is probably the most important decision you have to make when designing a new class.

In case there is no suitable superclass for the new class the base class Root of the class hierarchy has to be used -- Root is the superclass of all GRAPE classes.



SFB 256 Universität Bonn and IAM Universität Freiburg

Copyright © by the Sonderforschungsbereich 256 at the Institut für Angewandte Mathematik, Universität Bonn.