Professional Documents
Culture Documents
NET Developers
Class Diagrams
Classes
class Account
class Account
{
}
{
}
Account
Class Account
Class Account
End Class
End Class
Attributes
Account
- balance : Single = 0
- limit : Single
class Account
class Account
{
{
private float balance = 0;
private float balance = 0;
private float limit;
private float limit;
}
}
Class Account
Class Account
[visibility] [/] attribute_name[multiplicity] [: type [= default_value]]
Account
- balance : Single = 0
- limit : Single
+ deposit(amount : Single)
+ withdraw(amount : Single)
Operations
[visibility] op_name([[in|out] parameter : type[, more params]])[: return_type]
class Account
class Account
{
{
private float balance = 0;
private float balance = 0;
private float limit;
private float limit;
public void deposit(float amount)
public void deposit(float amount)
{
{
balance = balance + amount;
balance = balance + amount;
}
}
Class Account
Class Account
Private balance As Single = 0
Private balance As Single = 0
Private limit As Single = 0
Private limit As Single = 0
Public Sub deposit(ByVal amount As Single)
Public Sub deposit(ByVal amount As Single)
balance = balance + amount
balance = balance + amount
End Sub
End Sub
Public Sub withdraw(ByVal amount As Single)
Public Sub withdraw(ByVal amount As Single)
balance = balance - amount
balance = balance - amount
End Sub
End Sub
End Class
End Class
class Account
class Account
{
{
private float balance = 0;
private float balance = 0;
public float limit;
public float limit;
protected int id;
protected int id;
internal int databaseId;
internal int databaseId;
Account
- balance : float = 0
+ limit : float
# id : int
~ databaseId : int
+ deposit(amount : single)
-withdraw(amount : single)
# getAvailableFunds() : single
~ getDatabaseId() : int
+ = public
- = private
# = protected
~ = package
Visibility C#
}
Class Account
Class Account
Account
- balance : Single = 0
+ limit : Single
# id : Integer
~ databaseId : Integer
+ deposit(amount : Single)
-withdraw(amount : Single)
# getAvailableFunds() : Single
~ getDatabaseId() : Integer
+ = public
- = private
# = protected
~ = package
Visibility VB.Net
class Person
class Person
{
{
private static int numberOfPeople = 0;
private static int numberOfPeople = 0;
private string name;
private string name;
private Person(string name)
private Person(string name)
{
{
this.name = name;
this.name = name;
numberOfPeople++;
numberOfPeople++;
}
}
Person
- numberOfPeople : int
- name : string
Person
- numberOfPeople : Integer
- name : String
+ createPerson(name : String) : Person
+ getName() : String
+ getNumberOfPeople() : Integer
- New(name : String)
Associations C#
multiplicity
1
b
A
B
b:B
Equivalent to
role name
class A
class A
{
{
}
A a = new A();
A a = new A();
B b = a.b;
B b = a.b;
class B
class B
{
{
}
}
10
11
Associations VB.Net
multiplicity
1
b
A
B
b:B
Equivalent to
role name
Class A
Class A
Public b As New B()
Public b As New B()
End Class
End Class
Class B
Class B
End Class
End Class
12
Bi-directional Associations C#
multiplicity
A
B
role name
b:B
Equivalent to
B
a:A
class A
class A
{
{
public B b;
public B b;
public A()
public A()
{
{
b = new B(this);
b = new B(this);
}
}
}
A a = new A();
A a = new A();
B b = a.b;
B b = a.b;
A a1 = b.a;
A a1 = b.a;
System.Diagnostics.Debug.Assert(a == a1);
System.Diagnostics.Debug.Assert(a == a1);
class B
class B
{
{
public A a;
public A a;
public B(A a)
public B(A a)
{
{
this.a = a;
this.a = a;
}
}
}
Jason Gorman 2005. All rights reserved.
13
Bi-directional Associations
VB.Net
multiplicity
A
B
b:B
Equivalent to
role name
Class A
Class A
Public b As B()
Public b As B()
Sub Ne w()
Sub Ne w()
b = New B(Me)
b = New B(Me)
End Sub
End Sub
End Class
End Class
Class B
Class B
Public a As A
Public a As A
Public Sub New(ByRef a As A)
Public Sub New(ByRef a As A)
Me.a = a
Me.a = a
End Sub
End Sub
End Class
End Class
B
a:A
14
Address
15
1..2
1..*
accounts
Customer
Account
accounts[1..*] : Account
Equivalent to
class Customer
class Customer
{
{
Class Customer
Class Customer
// accounts[1..*] : Account
// accounts[1..*] : Account
public System.Collections.ArrayList accounts = new ArrayList();
public System.Collections.ArrayList accounts = new ArrayList();
accounts[1..*] : Account
accounts[1..*] : Account
Public accounts As New ArrayList()
Public accounts As New ArrayList()
public Customer()
public Customer()
{
{
Account defaultAccount = new Account();
Account defaultAccount = new Account();
accounts.Add(defaultAccount);
accounts.Add(defaultAccount);
}
}
16
HardwareDevice
1
ShoppingBasket
1..*
OrderItem
17
Generalization
Person
Employee
Class Person
Class Person
class Person
class Person
{
{
}
}
End Class
End Class
Class Employee
Class Employee
Inherits Person
Inherits Person
End Class
End Class
18
Realization
IPerson
<<interface>>
IPerson
OR
Employee
Employee
Interface IPerson
Interface IPerson
interface IPerson
interface IPerson
{
{
}
}
End Interface
End Interface
Class Employee
Class Employee
Implements IPerson
Implements IPerson
End Class
End Class
19
Overriding
Abstract classes
Dependencies
Qualified associations
Association classes
More on associations, visibility & scope
Information hiding
20
Class Diagrams
Implementation Diagrams
Sequence Diagrams
Packages &
Model Management
Activity Diagrams
Model the flow of use
cases and single and
multi-threaded code
UML for
.NET
Statechart Diagrams
Premium Package
Design Principles
Design Patterns
Create w ell-designed
software thats easier to
change and reuse
Available
exclusively from
www.parlezuml.com
21