197
Access Designations
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
Commas separate the parameters in the parameter list.
+getCompanyName(parameter1, parameter2, parameter3):String
I like keeping the object models as simple as possible.Thus, I normally include only
the class name, attributes, and methods in the class diagrams.This allows us to concentrate
on the big-picture of the design and does not place focus on details. Including too much
information (like parameters) in the class diagrams makes the object-model difficult to
read.This is one of those issues that depends on your specific tastes.
Access Designations
As mentioned previously, the plus signs (+) and minus signs (-) to the left of the attributes
and methods signify whether the attributes and methods are public or private.The attrib-
ute or method is considered private if there is a minus sign.This means that no other class
can access the attribute or method; only methods in the class can inspect or change it.
If the attribute or method has a plus sign to the left, the attribute or method is public,
and any class can inspect or modify it. For example, consider the following:
-companyNumber:float
+companyAge:int
In this example, companyNumber is private, and only methods of its class can do any-
thing with it. However, companyAge is public, and thus it is fair game for any class to ac-
cess and modify it.
If no access designation is present in the code, the system considers the access to be the
default, and no plus or minus is used:
companyNumber:float
companyAge:int