[an error occurred while processing this directive]
The concepts of cohesion and coupling are important consideration in the design of a class. You should aim for a class that be easily used and understood without having to understand the implementation. Good design and good documentation are both necessary to acheive this goal.
This section should be brief. Consider the following questions. From the answers, select a few sentences that serve best to help a programmer identify the kind of role that the class plays.
Object
.
For Java programming, a class can extend one other class, which is called its superclass. A class may also implement any number of interfaces. To avoid duplication of information and the resulting maintenance headaches, the documentation for a class usually only describes new features and new behavior added by the class to features inherited from the superclass or interfaces. Then client specification readers will need links to the superclass and interface documentation.
The model that you present should not contain implementation-dependent concepts. When methods are mentioned in the client data model, you can put in HTML links to the method specifications below.
Here are some questions to consider when describing the client data model.
Achieving data integrity requires a coordination between constructors and other methods. The constructors have the responsibility of creating objects that meet data integrity constraints. Other methods must be designed to maintain the constraints.
A class will often provide getter and/or setter methods for each object
attribute.
A getter returns the value of an attribute and a setter
sets its value.
If it is desirable to make an attribute read only or its value is computed
from other object attributes then its setter should be omitted.
For consistency, is is best to use the names
get
Attribute for getter methods and
set
Attribute for setter methods, where
Attribute is the name of the attribute with its first letter
capitalized.
An exception will generate an error message and terminate the program unless some method in the current active chain of calls catches the exception. This results in a flexible mechanism for handling errors - the server detects the error, but is not forced to handle the error by itself. Clients, direct or indirect, can intervene,, allowing the decision of how to handle the error to be made at a level where more context is available.
It is extremely useful for a method to check if its preconditions are met and to throw an exception if the preconditions are violated. The primary reason for this is that clients make mistakes, calling methods incorrectly. The clients will get much better fedback about an error if the server immediately thows an exception. Otherwise, symptoms of the error may not appear until much later, when it is no longer clear what component is causing the problem.
The client usually makes no attempt to catch precondition violation exceptions, so that the program terminates with an error message. This error message is not intended for viewing by the users of a program. It is a sanity check that informs writers of client code that there is a problem.
When the client is testing software, it may be desirable to catch precondition violation exceptions. For test software it is often useful to be able to continue the testing in spite of errors.
Sometimes, when run time is an important consideration, precondition violation checks may be omitted from the production version of software. Even then, it is usually best to include the checks during development.
public
in Java.
Clarity, precision, and conciseness are important qualities to consider
in this section.
When writing the method specifications, put yourself in the clients shoes.
Describe what the method is doing rather than how it is doing it.
It can be helpful to divide the methods into categories of related
methods.
The quality of method specifications is dependent on the design of the methods as well as the words that you use to describe them. You should spend considerable time working on the design before writing the specifications. Before filling out this section, you may find it easier to work with index cards for your methods.
Pay particular attention to cohesion. If you find that you cannot precisely specify a method in a sentence or two then you are probably trying to do too much with it. Reevaluate it to see if it can be broken up into more primitive methods.
You can often make method specifications clear and concise without sacrificing precision by using concepts defined in the Client Data Model section. If you find that there are repeated lengthy phrases in the method specifications then introduce terminology in the Client Data Model section to simplify the repetion.
Your class may have methods that are intended for internal use. These methods should not be mentioned here. They will be included in the class implementation specifications.