When you want to represent a class, you display it as a rectangle. This rectangle contains three parts: the name, attributes, and operations. For an example of a class view the figure on the right.
It is common practice to, when writing class names, to exclude spaces and underscores, and to capitalize each word. So, if you wanted to name a class “university student”, the correct format would be “UniversityStudent”. Attributes and operations on the other hand, also exclude spaces and underscores but utilizes camelCase. What this means is that the first word’s starting letter is always lowercase, but the following words’ starting letters should be capitalized. For example, if you were to have an attribute “first name”, you would write it “firstName”. Same with the operation “find book number”, which would be “findBookNumber”.
Attributes also have a type. If you are familiar with coding languages like Java or C++, then you can think of them as the same as variable types. The more common attribute types include:
Attribute | Description |
string |
means that the value contains text (e.g. “Bill”, “5 days”) |
char |
means that the value is one character long (e.g. ‘i’, 1) |
int |
means that the value is a number excluding decimals |
float |
means that the value is a number that includes decimals |
bool |
means that the value is either “true” or “false” |
void |
means that there is no value |
When identifying an attribute’s type you place it after the attribute name, like this: “firstName:String”. Operations also use types when taking in arguments and when identifying the return object type. The format for putting the operation type is “operationName( int argument1, String argument2 ):String. If you don’t want your operation to return an object, you use the type “void”
When naming your class keep in mind the following guidelines:
When naming your attributes keep in mind the following guidelines:
When naming your operations keep in mind the following guidelines: