Upload
clyde-black
View
219
Download
1
Embed Size (px)
Citation preview
Introduction to Java Class Diagrams
Classes
class Account
{
…
}
Account
Attributes
class Account
{
float balance = 0;
float limit;
}
Account
balance: float = 0limit: float
[visibility] attributeName [multiplicity] [: type [ = initialValue ] ]
Visibility
class Account
{
private float balance = 0;
private float limit;
}
Account
- balance: float = 0- limit: float
+ public- private# protected~ package
Operations (methods)
class Account
{
private float balance = 0;
private float limit;
public void deposit(float amount)
public void withdraw(float amount)
}
Account
- balance: float = 0- limit: float
[visibility] methodName( [parameter: type]* ) [ : returnType]
+ deposit( amount: float )+ withdraw( amount: float )
Class scope
class Person
{
private static int numPeople;
private String name;
public String getName()
public static int getNumPeople()
}
Person
- numPeople: int- name: String
+ getName() : String+ getNumPeople() : int
CompositionA comprises local objects that die when A dies
class Basket
{
Item item = new Item();
}
Basket Item
Aggregationcomprised of sharable objects
class Computer{ Device dev;
Computer(Device dev) { this.dev = dev; }}
Computer Device
Multiplicities
class Basket
{
Item item = new Item();
}
Basket Item1
Multiplicities
class Basket
{
Item[] item = new Item[5];
}
Basket Item5
Multiplicities
class Basket
{
// may or may not exist
Item item;
}
Basket Item0..1
i..j means i <= # objects <= j
Multiplicities
class Basket
{
List<Item> itemList = newArrayList<Item>();
}
Basket Item0..*
* means no a priori upper limit
Generalization (is a)class Person
{
…
}
class Employee extends Person
{
…
}
Person
Employee
Realizationinterface Person
{
…
}
class Employee implements Person
{
…
}
Person
Employee
Employee
Person