• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to map these in java

 
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Association -
Aggregation -
Composition -
If an object has reference of other object, then it is "associated"
How can I see the class structure and say - hey this is aggregation or this is composition !
in aggregation also we will have to use object reference only !
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An association relationship is a semantic connection between classes. It indicates that one class needs to communicate with another (for example, one class needs to send a message to the other).
An aggregation relationship is used to denote a whole/part relationship between classes. In this situation, one class logically contains another.
Eg: Transmission->Car
Transmission is part of a car, but it can also exist without a car. (Sitting on ground doing nothing, installed in a non-car vehicle like a submarine, etc)
Composition is used when the part classes cannot exist on their own; that is, each entity within the part class must be related to an associated whole class (mandatory relationships).
Eg: Employee->Department
An employee is useless without a department to work in.
 
Kalpesh Soni
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
me = poor java guy !
please explain how would the code differ in these conditions
is dependency in uml, one of these or is it 4th !?
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

please explain how would the code differ in these conditions


I see SCJP at the bottom.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kalpesh Soni:
If an object has reference of other object, then it is "associated"


Yes, but that's not the only way to have an association.


How can I see the class structure and say - hey this is aggregation or this is composition !


Generally speaking, you can't. It's nothing that has a 1:1 mapping to code, but rather influences how one object uses the other. And most often, it is rather unimportant to know, too.
Bobs book explains this in more detail.
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bobs book explains this in more detail.


Thats cool!
 
Author
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kalpesh Soni:
Association -
Aggregation -
Composition -


You aren't alone.
Association is simply when one class contains a variable that holds a reference to another:
<pre>
class A {
private B itsB;
}
|A|----------->|B|
itsB
</pre>
Aggregation is exactly the same thing, except that instances related by aggregation cannot aggregate themselves. i.e. There can be no cycles in the instance graph. i.e. An aggregate cannot be its own aggregee.
This distinction is so narrow that I have given up ever using aggregation. There is virtually no way to identify aggregation by looking at the source code. I also find that because nobody realy knows what aggregation is, everyone uses it for lots of different things.
Composition is used when one object is responsible for the lifetime of another. This is more common in C++ than in Java. In Java, the garbage collector has all the lifetime responsibility. In C++ certain classes are responsible for seeing to it that certain objects are destroyed. Those classes have Composition relationships to the classes of the destroyed objects.
<pre>
class A {
private:
B* itsB;
public:
A() {itsB = new B();}
virtual ~A() {delete itsB;}
};
|A|<#>--------->|B|
itsB
</pre>
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic