Chapter 18. Building Class Hierarchies


In Chapter 1, "Introduction to Java," we mentioned that one of the strengths of Java is that it allows you to develop class hierarchies. Hierarchies help you to organize your code and they facilitate code reuse. Because of inheritance, you can place common methods higher in the class hierarchy so they can be accessed by any number of classes lower in the hierarchy. In this chapter, we will go through the process of designing and implementing a class hierarchy to model a gas mixture, but the concepts and design strategies demonstrated here are applicable to all class hierarchies.

Developing class hierarchies is as much a design problem as it is one of programming. You must first think about the best way to create your hierarchy and there are many different approaches. For instance, should the root of your class hierarchy be a concrete class or an abstract class, or should an interface define the blueprint for the classes? Oftentimes, there will be no "right" answer. If you don't like the way the class hierarchy is created in this chapter and can think of a better way, more power to you! For a more detailed reference on object-oriented programming concepts, consult Thinking in Java by Bruce Eckel.

The specific topics we will discuss in this chapter are ”

  • Defining the state and behavior of a gas mixture

  • The general class hierarchy structure

  • AbstractGas class

  • PerfectGas class

  • Air class

  • RealGas class

  • Species class

  • N2 class

  • N class

  • NitrogenGas class



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net