Download presentation
Presentation is loading. Please wait.
Published byClyde Black Modified over 9 years ago
1
Introduction to Java Class Diagrams
2
Classes class Account { … } Account
3
Attributes class Account { float balance = 0; float limit; } Account balance: float = 0 limit: float [visibility] attributeName [multiplicity] [: type [ = initialValue ] ]
4
Visibility class Account { private float balance = 0; private float limit; } Account - balance: float = 0 - limit: float + public - private # protected ~ package
5
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 )
6
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
7
Composition A comprises local objects that die when A dies class Basket { Item item = new Item(); } BasketItem
8
Aggregation comprised of sharable objects class Computer { Device dev; Computer(Device dev) { this.dev = dev; } ComputerDevice
9
Multiplicities class Basket { Item item = new Item(); } BasketItem 1
10
Multiplicities class Basket { Item[] item = new Item[5]; } BasketItem 5
11
Multiplicities class Basket { // may or may not exist Item item; } BasketItem 0..1 i..j means i <= # objects <= j
12
Multiplicities class Basket { List itemList = newArrayList (); } BasketItem 0..* * means no a priori upper limit
13
Generalization (is a) class Person { … } class Employee extends Person { … } Person Employee
14
Realization interface Person { … } class Employee implements Person { … } Person Employee Person
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.