Java Reference
In-Depth Information
existing class may be part of the Java standard class library, part of a solution to
a problem we've solved previously, or part of a library that can be bought from a
third party. These are all examples of software reuse.
Assigning Responsibilities
Part of the process of identifying the classes needed in a program is the process
of assigning responsibilities to each class. Each class represents an object with
certain behaviors that are defined by the methods of the class. Any activity that
the program must accomplish must be represented somewhere in the behaviors of
the classes. That is, each class is responsible for carrying out certain activities, and
those responsibilities must be assigned as part of designing a program.
The behaviors of a class perform actions that make up the functionality of a
program. Thus we generally use verbs for the names of behaviors and the methods
that accomplish them.
Sometimes it is challenging to determine which is the best class to carry out a
particular responsibility. Consider multiple possibilities. Sometimes such analysis
makes you realize that you could benefit from defining another class to shoulder
the responsibility.
It's not necessary in the early stages of a design to identify all the methods that
a class will contain. It is often sufficient to assign primary responsibilities and
consider how those responsibilities translate to particular methods.
SELF-REVIEW QUESTIONS (see answers in Appendix N)
SR 7.4
How can identifying the nouns in a problem specification help you
design an object-oriented solution to the problem?
SR 7.5
Is it important to identify and define all of the methods that a class
will contain during the early stages of problem solution design?
Discuss.
7.3 Static Class Members
We've used static methods in various situations in previous examples in the topic.
For example, all the methods of the Math class are static. Recall that a static
method is one that is invoked through its class name, instead of through an object
of that class.
Not only can methods be static, but variables can be static as well. We declare
static class members using the static modifier.
VideoNote
Exploring the static
modifier.
 
Search WWH ::




Custom Search