HowTo CreateAClassDiagramm
HowTo CreateAClassDiagramm
Attributes
After you have learned from task 1 (Creating an object diagram) that objects are used to clearly
structure the relevant information, the necessary attributes for objects (instances) of the class Movie
can be identified as:
Since the blueprint of a class applies to all objects of this type, of course no object-specific values for
the attributes can be specified in the class diagram. Specifying a value with = means an initial value
(start value), if possible. Additional specifications may be required (in curly brackets). The data type of
any attribute must be defined in the blueprint (see slide 67 for a collection of basic data types).
String is the data-type for any text content (sequence of characters). Integer (int) stands for any
integer value, even negative values are possible (signed integer). Image is used within this example
for any picture data-format used for a cinema-poster, e.g. .jpg, .gif, .bmp, .png, .tif, …
Operations
The attributes map the information of the application to data (static model). The entire functionality of
the application is ultimately realized through the entire set of operations (dynamic model) of all
classes. An operation of a class is a function, a method or simply a service provided by a specific
object of this class (instance method).
Since direct access to the data values of the objects is always restricted (private), each use of the
attribute values must be implemented using appropriate operations. For example, the display of the
movie title on a web page must be done using the getTitle() operation, which returns the value of the
title attribute as a character string from a specified object of type Movie (instance operation)
Most operations fall into the following categories: (see slide 70):
The parameter list between braces contains all information and corresponding data types that a
method needs to perform its service. Getters usually have no parameters, since they perform their
service by accessing the object's attributes. That is, the instance methods of a class can read or
change the attribute values of that instance for which the method is activated (called). Setter always
need the new value to set for the specified attribute; so they need at least one parameter and have
on the other hand no return value.
For attributes that contain a set of values (e.g. genres of a movie), two methods are usually provided
for editing this set: addGenre(…)/removeGenre(…).
It is very difficult for non-programmers to understand what a method is and what it is used for.
However, as a programmer, all I do during implementation is to implement new methods by using
(calling) existing methods of predefined classes. Please note the mandatory UML notation for methods
(see solution).