File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Are Setters described as  Aggregation/Composition? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Are Setters described as  Aggregation/Composition?" Watch "Are Setters described as  Aggregation/Composition?" New topic
Author

Are Setters described as Aggregation/Composition?

Peter Kovac
Ranch Hand

Joined: Aug 08, 2010
Posts: 42
Hi,

I have a code like this, where Foo is passed to Bar (e.g. by Spring wiring):


Will UML look like this or is it a simple dependency?

Thanks,


Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

In my opinion, you can't tell from an example like that. It depends on the meanings of Foo and Bar, and more importantly on the meaning of the relationship between them. Can you consider the Foo to be part of the Bar? If so then it's probably an aggregation or a composition. So you really need a more concrete example to say anything definite.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

The setter has nothing to do with composition or aggregation. The two terms are about a relationship between two or more objects. Whereas composition implies ownership, aggregation doesn't. That is, with composition, if the "owning" object goes away, so does the "owned" object. With aggregation, the aggregated object can still continue to exist even without the aggregating object. See http://en.wikipedia.org/wiki/Object_composition#Aggregation


Junilu - [How to Ask Questions] [How to Answer Questions]
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

I suppose that one could argue that using a setter to establish a relationship implies one or the other but I can give examples that show this is not true. If you say that invoking a setter implies aggregation, a setter implementation could clone/copy the object passed in and "own" the clone, thus, it's composition. The reverse argument could be made in favor of aggregation. I suspect that in most cases where an object reference is passed to a setter, it does indeed establish an aggregation relationship but you should not assume that is always the case.
Wirianto Djunaidi
Ranch Hand

Joined: Mar 20, 2001
Posts: 210

It is not as simple of translating from code to UML. UML is supposed to express your design & intention, so from conceptual point of view aggregation & composition hold different meaning..but when it is translated to code they might end up being implemented the same way. This is similar with design patterns, a lot of design patterns have similar implementation code-wise but the design pattern itself convey the meaning or intent that the designer want to solve.

Having said that, from my previous experience working on code generation portion of UML tools, typically the translation from UML to Code are:
- Aggregation/Composition implemented as an array or collection
- regular link implemented as standard single attribute of the object

Setter/getter has no direct meaning toward the relationship whether it is simple relationship or aggregation/composition, from UML design point of view it is irrelevant. Most UML tools can be customized to generate getter/setter, parameterized constructor, or both for all the important attributes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Are Setters described as Aggregation/Composition?
 
Similar Threads
Inner Class Doubts
Implementing Data interface in local and network mode
Instance Doubt
Why it is illegal to use abstract and static modifiers together in method declaration ?
Argument-defined anonymous class call