Reputation: 93
my program runs through source code easily enough and I can detect easy relationships such as implementation or inheritance using extends just by searching for where the class is defined. However, I'm a bit stuck with ideas on how to detect other relationships such as if a class has association or aggregation with another class.
So far I have tried parsing the code and looking for where other methods are called but I'm not sure of an exact code definition of these relationships.
Sorry if I am being unclear I can try and explain better if you don't understand just let me know in the comments.
Upvotes: 0
Views: 590
Reputation: 24464
The problem is that there is not any strict definition how to translate Java classes relations in associations, dependencies and aggregations. You should set the rules yourself, only check them against the UML standard.
I would advice the following :
UML Java
Dependency A->B Class A mentions class B
Association A->B Class A has reference {that can have reference} (it is recursive!} to class B
Composition A->B Class A has array or collection of B or of references to B AND
(black diamond) no other classes have instances of B or references to them,
either single or collective (arrays, collections)
Shared aggregation A->B Class A has array or collection of B or of references to B AND
(empty diamond) at least one other class has an instance of B or references to such,
either single or collective (arrays, collections)
If according to the last rule, you get two-sided shared aggregation A-B, it is forbidden. So, change it to two mutual shared aggregations.
Remember, that Association and Shared aggregation have NO strict definitions, only limitations.
Upvotes: 0
Reputation: 5443
Aggregation and composition both look like member variables in Java
e.g.
class MyClass {
private HerClass h;
}
MyClass HAS-A HerClass member - so that's composition or possible aggregation. You could tell the difference based on whether MyClass creates the HerClass - that would PROBABLY be composition.
Association is based on dependency. Why don't you use the imports to find out which classes are depended on? Or you could scan any use of type names in the code - the moment a type name is mentioned, there's a "uses" association.
Upvotes: 1