advertisement

Search Tips
Articles  |   Tutorials  |   Reviews  |   Dev Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source Code  |  

Browse DevX
DevX Updates - Sign Up Here


Partners & Affiliates



advertisement

Articles : Advanced Topics in Java :
Unified Modeling Language :

Contents
Classes and Inheritance
Associations
Roles
Attributes and Behaviors
Abstract Classes, Interfaces, and Relationships
Conclusion

Associations and Roles

Roles

Eventually a name can be assigned to the visible ends of the relation. Such a name is called a role because it expresses what role the accessible class plays within the context of the other class. Therefore, role names should be nouns.

Notice that the role1 name appears next to the Class2 even though it describes the role within Class1. This is just the way the Rational Rose we used to draw these diagrams does it.

A role is prefixed either with a "+", a "-", or a "#" sign which expresses how accessible the role is ,or what its visibility is.

+ public, accessible from all classes.

# protected accessible to only classes with a generalize relationship with this class.

- private accessible only to the class itself.

Unlike associations, roles correspond to instance variables of the class and the private/public/protected notation corresponds exactly to their modifiers in Java.

Another symbol can appear at one end of an association:

An association with such a diamond is called an aggregation (or, if the diamond is filled, is called a containment), which means that the "incoming" object can exist only while the "outgoing" one exists or only when stored within the "outgoing" object. While these concepts are important in other languages (e.g. in C++), they have no meaning in Java programs. I will mostly leave these adornments out to simplify the diagrams.

Two classes can relate to each other in more than one way. To model such associations, you have to bend the associations' lines.

To give an example, each AWT component has a foreground and a background color, i.e. the class java.awt.Color has two roles within the class java.awt.Component.

Notice the 0..* label in the above diagram. This "multiplicity" adornment and others (like 1..*, 2, 10, n) means that this role needs to be represented by several objects.

An object of a class can have a role within the class itself. The corresponding association then starts and ends in the same class.

In the resulting code such an association means that there is an instance variable of the same class, i.e. that the class represents a "recursive data type". If the role is given a multiplicity adornment:

This means that a class contains numerous references to itself. This is a basis for hierarchical data structures.

To recap, the three types of relationships are:


Association
- - An association is a bi-directional connection between classes.
- - An association is shown as a line connecting the related classes
Aggregation
- - An aggregation is a stronger form of relationship where the relationship is between a whole and its parts.
- - An aggregation is shown as a line connecting the related classes with a diamond next to the class representing the whole.
Dependency
- - A dependency relationship is a weaker form of relationship showing a relationship between a client and a supplier where the client does not have semantic knowledge of the supplier.
- - A dependency is shown as a dashed line pointing from the client to the supplier.

NEXT


The author has over three and a half years of experience on developing web and object oriented application with a development focus on server side and enterprise Java .He is a regular writer for the European publication "Programmez!" and writes on and of for some online publications. He can be reached at sameertyagi@usa.net

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

internet.com logo


JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.
Blackmail Applet
This applet prints out text that looks like letters cut out of a newspaper. You can specify the text, the width and height of the applet and the delay after each letter. Future versions will have more parameters.
JB User Poll
What is your primary tool for learning Java?
The JavaBoutique Top 15:
1. articles.rdf
2. welcomead
3. applets.rdf
4. quickserv
5. 3DMaze
6. dotz
7. Froz_Bubb
8.
9. KaaBlitz
10. anglefinder
11. ChompText
12. DS_ClockWipe
13. Pool
14. Search2
15. PacMan
Want more? Check out our Top 100!

Refer-It
Affiliate Program and Referral Directory.
New on internet.com
Google IM Not Talking to Other Jabbers
Newly-launched Google Talk IM service doesn't connect to other open source Jabber servers and users -- at least not yet.

Printer Sets Good Example for Small Business Security
While surveys suggest that small businesses aren't prepared for ever-present security dangers, this Boston-area printer has maintained a pristine operation since a scare six years ago.

VoIP Gizmo Comes to Universities
As student gear up for back to school, a SIP-based initiative aims to VoIP-enable universities around the world for free calling.



Copyright 2002 INT Media Group, Incorporated. All Rights Reserved.
Legal Notices,  Licensing, Reprints, & Permissions,  Privacy Policy.
http://www.internet.com/