Chapter 4. The Anatomy of a Class

 <  Day Day Up  >  

We have already discussed in great detail object-oriented (OO) concepts and the difference between the interface and the implementation. No matter how well you think out the problem of what should be an interface and what should be part of the implementation, the bottom line always comes down to how useful the class is and how it interacts with other classes. A class should never be designed in a vacuum , for as might be said, no class is an island. When objects are instantiated , they almost always interact with other objects. An object can also be used within another object, or be inherited. The following section is a bit of a dissection of a class, and the rest of the chapter offers some guidelines that you should consider when designing classes.

In this chapter we'll examine a simple class and then take it apart piece by piece. We will continue using the cabbie example presented in Chapter 2, "How to Think in Terms of Objects."

In this chapter, we'll discuss the following parts of a class:

  • Class name ” How the class name is identified

  • Comments ” How to create comments to document your code

  • Attributes ” How to define attributes for use in the class

  • Constructors ” Special methods used to properly initialize a class

  • Accessors ” Methods that are used to control access to private attributes

  • Public interface methods ” How to define public interface methods

  • Private implementation methods ” How to define private implementation methods

Only a Template

This class is meant for illustration purposes only. Some of the methods are not fleshed out (meaning that there is no implementation) and simply present the interface.


 <  Day Day Up  >  


Object-Oriented Thought Process
Object-Oriented Thought Process, The (3rd Edition)
ISBN: 0672330164
EAN: 2147483647
Year: 2003
Pages: 164
Authors: Matt Weisfeld

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