150 likes | 351 Views
Introduction to Java Class Diagrams. Classes. class Account { … }. Account. Attributes. class Account { float balance = 0; float limit; }. Account. balance: float = 0 limit: float. [visibility] attributeName [multiplicity] [: type [ = initialValue ] ]. Visibility.
E N D
Classes class Account { … } Account
Attributes class Account { float balance = 0; float limit; } Account balance: float = 0 limit: 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 + deposit( amount: float ) + withdraw( amount: float ) [visibility] methodName( [parameter: type]* ) [ : returnType]
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(); } 1 Basket Item
Multiplicities class Basket { Item[] item = new Item[5]; } 5 Basket Item
Multiplicities class Basket { // may or may not exist Item item; } 0..1 Basket Item i..j means i <= # objects <= j
Multiplicities class Basket { List<Item> itemList = newArrayList<Item>(); } 0..* Basket Item * means no a priori upper limit
Generalization (is a) Person class Person { … } class Employee extends Person { … } Employee
Realization interface Person { … } class Employee implements Person { … } Person Employee Person Employee