Attributes and Methods

 <  Day Day Up  >  

Attributes and Methods

Besides presenting the structure of the class, the class diagram also presents information about the attributes and methods.

Attributes

Normally, attributes are not thought of as having signatures; methods get all the credit. However, an attribute has a type, and this type is represented in the class diagram. Consider the two attributes that are in the Cabbie example:

 
 -companyName:String -name:String 

Both of these attributes are defined as strings. This is represented by the name of the attribute followed by the type (in these cases, String ). There could have been attributes that were defined as int and float as well, as in this example:

 
 -companyNumber:float -companyAge:int 

By looking at the class diagram, you can tell the type of the parameter.

Methods

The same logic used with attributes works for methods. Rather than express the type, the diagram shows the return type of the method.

If you look at the following snippet from the Cabbie example, you can see that the name of the method is presented, along with the return type and the access modifier (for example, public , private ):

 
 +Cabbie: +giveDirections:void +getCompanyName:String 

As you can see here, in all three cases the access modifier is public (designated by the plus sign). If a method were private, there would be a minus sign. Each method name is followed by a colon that separates the method name from the return type.

It is possible to include a parameter list, in the following manner:

 
 +getCompanyName(parameter-list):String 

The parameters in the parameter list are separated by commas.

 
 +getCompanyName(parameter1, parameter2, parameter3):String 
 <  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