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 ”
|