


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















In this lecture we will be studying Class Models which are a part of the Unified Modeling Language (UML).
Of the various models in UML, we have the categories:
Use case models – describing a system from the users’ point of view; Static models – describing the elements of the system and their relationship; class models fall into this category; Dynamic models – describing the behaviour of the system over time.
In the Unified Modelling Language (UML), a class is shown in a class diagram as a rectangle giving its name:
Recall that we previously mentioned the noun identification technique to find potential classes.
There are two main (extreme) techniques used to find classes in general: Data-driven-design (DDD) – We identify all the data of the system and divide it into classes. We then assign particular responsibilities (methods) to these classes Responsibility-driven-design (RDD) – We identify all the responsibilities of the system and divide them into classes. We then find the data each class requires.
Class A and B are Associated if
an object of class A sends a message to an object of class B
an object of class A creates an object of class B
an object of class A has an attribute whose values are objects of class B or collections of objects of class B
an object of class A receives a message with an object of class B as argument
In other words, if some object of class A has to know about some object of class B
One annotation which is often used early is the multiplicity of an association This is so fundamental that we will spend some time thinking about it.
We can specify:
an exact number simply by writing it, e.g. 1
a range of numbers using two dots between a pair of numbers, e.g., 1..
an arbitrary, unspecified number using *****
Loosely, you can think of UML’s * as an infinity sign, so the multiplicity *1 .. ** expresses that number of copies can be anything between 1 and infinity.
The attributes of a class describe the data contained in an object of the class and their type
Most important are the operations of a class, which define the ways in which objects may interact.
Vehicle v = null;
v = new Car();
v.startEngine();
v = new Boat();
v.startEngine();
COMP201 - Software Engineering 13
Call Car startEngine() method
Call Boat startEngine() method
docsity.com
Important relationships which may exist between classes are called generalization. Conceptually this means that if class A is a generalization of class B , then the interface of class B must conform to the interface of class A.
Every attribute and operation of A will also be supported by B. In addition, B may contain some extra operations and data specific to its class.
Let’s see an example of this on the next slide…
COMP201 - Software Engineering 16
Animal Age: Integer getAge(): Integer
Cat
meow(): void
Dog
bark(): void
Animal any = new Animal(12); any.getAge(); any.meow(); any.bark();
Fine, returns 12 Error – No meow() method! Error – No bark() method! docsity.com
Animal any = new Cat(8); any.getAge(); any.meow(); any.bark();
COMP201 - Software Engineering 17
Animal Age: Integer getAge(): Integer
Cat
meow(): void
Dog
bark(): void
Fine, returns 8 Fine, object “meows” Error – No bark() method! docsity.com
One common way of checking for a good design and guiding its refinement is to use CRC cards.
CRC stands for Classes, Responsibilities, Collaborations.
Although CRC is not part of UML, they add some very useful insights throughout a development.
The name of a class , at the top
The responsibilities of the class , on the left-hand side
The collaborators of the class , which help to carry out each responsibility, on the right-hand side of the card.
The responsibilities of the class describe at a high level the purpose of the class’s existence : They are connected with the operations the class provides, but are more general than that might imply – i.e., they can be an abstraction of several operations.