0% found this document useful (0 votes)
45 views

UML For Java Developers: Class Diagrams

Uploaded by

vinaymadireddy
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

UML For Java Developers: Class Diagrams

Uploaded by

vinaymadireddy
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

UML for Java Developers

Class Diagrams

1
© Jason Gorman 2005. All rights reserved.
"I am currently working on a
team which is [in] the process
of adopting RUP and UML
UML for Java Developers (5 Days)
standards and practices. After Since Autumn 2003, over 100,000 Java and .NET developers have
one of our design sessions, I learned the Unified Modeling Language from Parlez UML
needed to lookup some (http://www.parlezum l.com) , making it one of the most popular
information and came across UML training resources on the Internet.
your site. Absolutely great!
Most [of] the information I've
had questions about is UML for Java Developers is designed to accelerate the learning
contained within your tutorials process by explaining UML in a language Java developers can
and then some." understand – Java!

From Requirements to a Working System


"Really great site... I have been Many UML courses focus on analysis and high-level design, falling
trying to grasp UML since the short of explaining how you get from there to a w orking system. UML
day I saw Visual Modeler. I
knew a few things but there for Java Developers takes you all the w ay from system
were gaps. Thanks to your site requirements to the finished code because that, after all, is w hy we
they have shrunk model in the first place.
considerably."
Learning By Doing
UML modeling is a practical skill, like driving a car or flying a plane.
"I went on a UML training
Just as w e don’t learn to drive just by looking at Pow erPoint
course three months ago, and
came out with a big folder full presentations, you cannot properly learn UML w ithout getting plenty
of hand-outs and no real of practice at it.
understanding of UML and how
to use it on my project. I spent Your skills w ill be developed by designing and building a w orking
a day reading the UML for piece of software, giving you a genuine understanding of how UML
.NET tutorials and it was a can be applied throughout the development lifecycle.
much easier way to learn.
'Here's the diagram. Now
here's the code.' Simple."
www.parlezuml.com/training.htm

advertisement
2
© Jason Gorman 2005. All rights reserved.
UML for Java Developers covers the most useful aspects of the
UML standard, applying each notation w ithin the context of an
iterative, object oriented development process

Use Case Diagrams Object Diagrams & Filmstrips


Model the users of the system Model snapshots of the running
and the goals they can achieve system and show how actions
by using it change object state

Class Diagrams Implementation Diagrams


Model types of objects and Model the physical components of a
the relationships between system and their deployment
them. architecture

Sequence Diagrams Packages &


Model how objects interact Model Management
to achieve functional goals Organise your logical and physical
models with packages

Activity Diagrams
Object Constraint Language
Model the flow of use cases
Model business rules and create
and single and multi-threaded unambiguous specifications
code

Statechart Diagrams User Experience Modeling


Model the behaviour of objects Design user-centred systems with
and event-driven applications UML

Design Principles Design Patterns


Create well-designed software Apply proven solutions to common
that’s easier to change and OO design problems
reuse

www.parlezuml.com/training.htm
3
© Jason Gorman 2005. All rights reserved.
Classes

class Account
class Account
Account
{
{
}
}

4
© Jason Gorman 2005. All rights reserved.
Attributes
class Account
class Account
{
{
private float balance = 0;
private float balance = 0;
Account private float limit;
private float limit;
- balance : Single = 0 }
- limit : Single }

[visibility] [/] attribute_name[multiplicity] [: type [= default_value]]

5
© Jason Gorman 2005. All rights reserved.
Account
- balance : Single = 0
Operations
- limit : Single
+ deposit(amount : Single) [visibility] op_name([[in|out] parameter : type[, more params]])[: return_type]
+ withdraw(amount : Single)

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;
}
}

public void withdraw(float amount)


public void withdraw(float amount)
{
{
balance = balance - amount;
balance = balance - amount;
}
}
}
}

6
© Jason Gorman 2005. All rights reserved.
class Account
class Account
{
{
private float balance = 0;
private float balance = 0;
Account public float limit;
public float limit;
protected int id;
- balance : float = 0 protected int id;
+ limit : float int databaseId;
int databaseId;
# id : int
~ databaseId : int public void deposit(float amount)
public void deposit(float amount)
+ deposit(amount : single) {
{
-withdraw(amount : single) balance = balance + amount;
balance = balance + amount;
# getAvailableFunds() : single }
~ getDatabaseId() : int }

private void withdraw(float amount)


private void withdraw(float amount)
{
{
balance = balance - amount;
balance = balance - amount;
}
}
+ = public
- = private protected int getId()
protected int getId()
# = protected {
{
~ = package return id;
return id;
}
}

int getDatabaseId()

Visibility
int getDatabaseId()
{
{
return databaseId;
return databaseId;
}
}
}
}

7
© Jason Gorman 2005. All rights reserved.
class Person
class Person
{
int noOfPeople = Person.getNumberOfPeople(); {
int noOfPeople = Person.getNumberOfPeople();
private static int numberOfPeople = 0;
Person p = Person.createPerson("Jason Gorman"); private static int numberOfPeople = 0;
Person p = Person.createPerson("Jason Gorman");
private String name;
private String name;

private Person(string name)


private Person(string name)
{
{
this.name = name;
this.name = name;
Person numberOfPeople++;
numberOfPeople++;
}
}
- numberOfPeople : int
- name : string
public static Person createPerson(string name)
public static Person createPerson(string name)
+ createPerson(name : string) : Person {
+ getName() : string {
return new Person(name);
+ getNumberOfPeople() : int return new Person(name);
- Person(name : string) }
}

public string getName()


public string getName()
{
{

Class & Instance


return this.name;
return this.name;
}
}

Scope
public static int getNumberOfPeople()
public static int getNumberOfPeople()
{
{
return numberOfPeople;
return numberOfPeople;
}
}
}
}

8
© Jason Gorman 2005. All rights reserved.
Associations
multiplicity

1 1 A
A B
b b:B

role name Equivalent to

class A
class A
{
{
public B b = new B();
public B b = new B(); A a = new A();
A a = new A();
}
} B b = a.b;
B b = a.b;

class B
class B
{
{
}
}

9
© Jason Gorman 2005. All rights reserved.
Bi-directional Associations
multiplicity

1 1 A
A B
a b b:B

role name Equivalent to


B

class A a: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;
class B
class B A a1 = b.a;
A a1 = b.a;
{
{ assert a == a1;
assert a == a1;
public A a;
public A a;
public B(A a)
public B(A a)
{
{
this.a = a;
this.a = a;
}
} 10
}
}
© Jason Gorman 2005. All rights reserved.
Association names & role
defaults
Lives at
Person Address

Default role name = address


Default multiplicity = 1

class Person
class Person
{
{
// association: Lives at
// association: Lives at
public Address address;
public Address address;

public Person(Address address)


public Person(Address address)
{
{
this.address = address;
this.address = address;
}
}
}
}

11
© Jason Gorman 2005. All rights reserved.
Multiplicity & Collections
1..2 1..* Customer
Customer Account
accounts accounts[1..*] : Account

Equivalent to

class Customer
class Customer
{
{
// accounts[1..*] : Account
// accounts[1..*] : Account
ArrayList accounts = new ArrayList();
ArrayList accounts = new ArrayList();

public Customer()
public Customer()
{
{
Account defaultAccount = new Account();
Account defaultAccount = new Account();
accounts.add(defaultAccount);
accounts.add(defaultAccount);
}
}
}
}

12
© Jason Gorman 2005. All rights reserved.
Aggregation & Composition
0..1 1..*
Computer HardwareDevice

Aggregation – is made up of objects that can be shared or exchanged

1 1..*
ShoppingBasket OrderItem

Co mposition – is composed of objects that cannot be shared or exchanged


and live only as long as the composite object

13
© Jason Gorman 2005. All rights reserved.
Generalization
Person

Employee

class Person
class Person
{
{
}
}

class Emp loyee extends Person


class Emp loyee extends Person
{
{
}
}

14
© Jason Gorman 2005. All rights reserved.
Realization
Person
<<interface>>
Person

OR

Employee Employee

interface Person
interface Person
{
{
}
}

class Emp loyee implements Person


class Emp loyee implements Person
{
{
}
}

15
© Jason Gorman 2005. All rights reserved.
www.parlezuml.com

16
© Jason Gorman 2005. All rights reserved.

You might also like