0% found this document useful (0 votes)
9 views

HowTo CreateAClassDiagramm

This document provides guidance on creating a class specification for movies using UML notation. It identifies the key attributes of a Movie class as title, synopsis, duration, and poster. Attributes define the data for class instances. Operations define the class's functionality and include constructors, getters, and setters. For the Movie class, example operations are listed such as getTitle() and setDuration() which access or modify attribute values. The parameters and return types of each operation are also specified according to UML standards.

Uploaded by

Ashish Ghaskata
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

HowTo CreateAClassDiagramm

This document provides guidance on creating a class specification for movies using UML notation. It identifies the key attributes of a Movie class as title, synopsis, duration, and poster. Attributes define the data for class instances. Operations define the class's functionality and include constructors, getters, and setters. For the Movie class, example operations are listed such as getTitle() and setDuration() which access or modify attribute values. The parameters and return types of each operation are also specified according to UML standards.

Uploaded by

Ashish Ghaskata
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Case study: Cinema

How to create a class specification using the example Movie

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:

 title: String {read only/frozen} {mandatory} {id}


 synopsis: String = “…“ {optional}
 duration: int {mandatory}
 poster: Image = null {optional} (null means undefined)

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):

 constructor: are always class-operations which create a new instance of a class


 getter: are always instance-methods which enable the reading of attribute values. They return the
value of the corresponding attribute using the respective data-type.
 setter: are always instance-methods, which override the current value of an attribute with a
specified new value. The new value must be of appropriate type and is parameter of these
operations. No value is returned (void).

A minimal framework of necessary operations for the class Movie are:


 create(title: String) : Movie (constructor, class-method)
 getTitle() : String
 getSynopsis() : String
 getDuration() : int
 getPoster() : Image
 getAgeRating() : AgeRating
 getGenres() : Set<Genre> (return a set of values !)
 setSynopsis(text: String) : void
 setDuration(minutes: int) : void
 setPoster(pic: Image) : void
 setAgeRating(ar: AgeRating) : void
 addGenre(new: Genre) : void (editing a set of values !)
 removeGenre(old: Genre) : void

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).

You might also like