Reputation: 23
Here's a very quick example for my problem:
http://img19.imageshack.us/img19/3575/workertool.png
(I'm not allowed to post the image here because I'm a new user)
The source code for both classes looks like this:
public abstract class Worker{
private Tool myTool;
}
public class ABCWorker extends Worker{
public ABCWorker(){
myTool = new ABCTool();
}
public work(){
tool = (ABCTool) myTool;
//use tool to do some work
}
}
How do I correctly model this in UML? In my opinion, there are only three possibilities:
1) The way I did it in the example. This is wrong, however, because it says that an ABCWorker can use any tool. However, it can only use an ABCTool.
2) Put a second association between ABCWorker and ABCTool. Obviously wrong because it would mean an ABCWorker uses two tools, an ABCTool and a generic one.
3) Only put one association between ABCWorker and ABCTool. Also wrong, because it omits the relationship between Worker and Tool.
So how should I do it?
Upvotes: 2
Views: 471
Reputation: 21
Option 2 is almost correct
2) Put a second association between ABCWorker and ABCTool. Obviously wrong because it would mean an ABCWorker uses two tools, an ABCTool and a generic one.
You define a new property ABCTools wich redefines the property tool.
http://www.uml-diagrams.org/uml-core.html#redefinable-element
class Worker {
myTool:Tool;
}
class HardWorker {
hammer:ABCTool {redefines myTool}
}
Upvotes: 2
Reputation: 1189
Some things just cant be shown on a class diagram. This for example, is one of those cases, where you cant really show the interaction between objects. And that is normal, because this is a class diagram.
If this is really important to you, then you should model it using a more appropriate diagram, in order to explain this.
Upvotes: 0