Static Modeling Using Class Diagrams
Static Modeling Using Class Diagrams
• Any class derived from the base class never inherits its
private attributes and private operations.
• Public visibility: Public attributes and Public operations
can be viewed and used outside the class in which they are
declared. If the attributes in the class Triangle had public
visibility then
• t1.base=10 // Allowed
• t1. height=20 //Allowed
Visibility of Attributes and
Operations contd..
• The UML symbol to denote public visibility for attributes and
operations is '+'.
• Any class derived from the base class inherits its public
attributes and public operations.
Qualified Association contd..
• Qualified associations can be used with 1 to many or many
to many associations.
• If relationship between Company and Person was many-to-
many then
Association Class
import java.util.*;
public class Person {
public Collection givesBirthTo;
}
Within a class Person, there will be a reference to a
collection of Persons
Multiple Associations between Two
Classes
• Two classes can have multiple associations between them.
• E.g. Many trains can arrive at a station and many trains can
leave a station.
Java Code for Multiple
Associations
public class Train {
public Station arriveAt;
public Station leave;
}
public class Station {
}
Composite Aggregation
• Aggregation indicates that the relationship between classes
is whole-part. There are two types of Aggregations:
composite aggregation and shared aggregation.
• Composite Aggregation-A whole-part association between
two classes such that the parts reside within the whole.
• Destruction of the whole results in automatic destruction of
the parts.
• Multiplicity on the part side can be many but on the whole
side it has to be zero or one.
• Denoted by a filled diamond
Depicting Composite Aggregation
Java Code for Composite
Aggregation
import java.util.*;
public class Form {
public Collection myLabel;
public Collection myTextBox;
}
public class Label {
public Form myForm;
}
public class TextBox {
public Form myForm;
}
Shared Aggregation
• A whole-part association between two classes such that a
part can reside within many wholes at the same time.
• Multiplicity on the part side can be many but on the whole
side it has to be other than one.
• Denoted by a hollow diamond.
Java code for Shared Aggregation
import java.util.*;
public class Team {
public Collection myPlayer;
}
import java.util.*;
public class Player {
public Collection myTeam;
}
Generalization
• An association between a general class and more specific class
(es).
• The specific class (es) contains extra behaviour of its/their own.
• The general class is called as the base class or superclass and the
more specific class is called as the derived class or subclass.
Generalization contd..
• It can also be represented as:
Java Code for Generalization
public class Parliamentarian {
}
public class LokSabhaMember extends Parliamentarian {
}
public class RajyaSabhaMember extends Parliamentarian {
}
Abstract Class