• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing UML Concepts in Java

 
Sreek Gupta
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is there any good document that tells how to implement UML conecpts like aggregation, composition, association, dependency, stereotypes in java?

I mean the aggregation can be shown as follows in java:

public class Car{
private Wheel wheels[];
public Car(Wheel w1, Wheel w2, Wheel w3, Wheel w4){
wheels[0] = w1;
wheels[0] = w2;
wheels[0] = w3;
wheels[0] = w4;
}
}

Like wise how can i implement other features of UML in java?


Regards,
Sreek
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See how UML For Java Programmers looks. A quick glance at the source code zip file looks like it follows a few designs from inception to completion, which ought to be pretty cool. Ooh! Slides from a presentation on the same topic. Uncle Bob is always good.

And note that he deliberately doesn't go to the level of detail of Aggregation vs Composition. Code doesn't really tell you much about either one. For example your example might be composition - a composed object doesn't necessarily have to compose itself.
[ June 19, 2006: Message edited by: Stan James ]
 
kri shan
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stan James, UML for java Programmers by Robert C Martin book doesn't cover the level of detail of Aggregation, Composite Aggreagartion, Dependency,... Can you mention any other book or link ?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UML is an abstraction is supposed to be an abstraction from the code, which means that in fact there isn't a simple one to one mapping from UML to code. That is, there is are plenty of different ways to implement association, aggregation and composition in Java, and deciding on which one to use is the creative part of the programming job - there cannot be a cookbook for that, in my not so humble opinion.

That doesn't mean that there can't be advice, though. Can you tell us more about where you are coming from, why you are asking this question, so that we are in a better position to help you?

How much do you know about the semantics of the UML concepts?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty sure Uncle Bob didn't go to that level of detail because he felt it largely didn't matter. To Ilja's question about the semantics ... exactly how would your expectations for behavior in a composition relationship differ from an aggregation relationship? That's not a trick question - I hope you really have some answers. Will you code objects differently to make that happen, or just use them differently?

In one project I felt it was important to fill in the composition decoration on diagrams to let others know one object was responsible for the life cycle of another. It told people something about the intent of the design and how they should use objects, but probably made no difference at all in the Class itself. I don't recall if it was important because of the language (not Java) or the framework we were using, or the skills of the team. But I haven't much bothered with it in more recent projects.

You mentioned the word "Dependencies". Uncle Bob is all over those! His "Agile Software Development" book (also called PPP for the subtitle) is a goldmine on dependency management ideas.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've found that if I apply the "tell, don't ask" principle to my designs it often comes up with composition-style associations. Here's a slightly contrived but mostly real example:



In this case the LocalDataSource object is private and entirely managed within the DBWrapper. That looks a lot like a composition to me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic