*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Example of Reflexive composition relation. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Example of Reflexive composition relation." Watch "Example of Reflexive composition relation." New topic
Author

Example of Reflexive composition relation.

Devesh H Rao
Ranch Hand

Joined: Feb 09, 2002
Posts: 687

Hi ppl,
i just was having a talk with my prof regarding the various types of relation ship between Objects such as aggregation,association composition and their practical examples.
we became stuck for an example of reflexive composition ..
can anybody help out with a practical example of the same
just curious ..!!!
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Reflexive composition is (as far as I know) used in a class diagram when one object refers to one or more other objects of the same type.
We might design a tree in which each Node holds a reference to a "parent" Node object and zero or more "child" Node objects.
We might design a list in which each Element object holds a reference to the "next" Element object.
We might design a system model in which each Person object holds a reference to a "next of kin" Person object.
And so on. Has that helped?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Devesh H Rao
Ranch Hand

Joined: Feb 09, 2002
Posts: 687

Hi frank,
thanx for the input
Reflexive Composition
1> The paret object spawns the child
2> Only the parent object knows the existance of the child
3> No object Other than the Parent can access the child object
4> The scope of the child is a long as the parent is in scope as the child is completely encapsulated by the parent.

A example for a composition would be a Thread and process where the process has no existance outside the thread....
i would like a example of reflexive composition where the parent and child are basically from the same class..
The examples u have provided i think do not fulfill the encapsulation req though i may be wrong....
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
1> The parent object spawns the child
2> Only the parent object knows the existance of
the child 3> No object Other than the Parent can
access the child object 4> The scope of the child
is a long as the parent is in scope as the child
is completely encapsulated by the parent.
...
i would like a example of reflexive composition
where the parent and child are basically from the
same class..

Ah. I'd missed the nuances of the "composition"
part. Strangely enough I was actually working
with one of these a couple weeks ago, although
there was no UML to show that it was.
In the system I am working on, there are several
"entity" style objects which hold data loaded
from a database (each aggregating the results of
several distinct queries and stored procedure
calls, and providing methods to update the
database from changed information). The original
(horrible) code had a lot of member variables
such as:
String networkId;
String controllerId;
int activeInterfaces;
Interface[] interfaces;
It also had an identical list of variables
String local_networkId;
String local_controllerId;
int local_activeInterfaces;
Interface[] local_interfaces;
and some clumsy code to copy from one group to
another, initialise the two groups, etc.
The original intention was to separate the
original values (loaded from the database) from
the ones modified by the user, so that when the
object is sent back to the database, only changed
values need be updated.
After several irritating bugs due to mistakes and
misunderstandings in updating this code, we
refactored it so that each class in question had
just one list of member variables, but also had a
reference to another instance of the same class,
created in the constructor. This enabled the
"secondary" object to hold the initial database
values for reference, but not to "get in the way"
of the functioning of the "primary" object.
Making the two objects instances of the same
class ensured that they would always have exactly
the same list of member variables.
I'm not holding this up as a particularly good
design, but given the original state of the code
it is certainly an improvement, and helps prepare
the ground for refactoring to more intelligent
designs later.
Has that helped?
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Sorry for the cramped format of that last post, I had to use a text-mode browser
Devesh H Rao
Ranch Hand

Joined: Feb 09, 2002
Posts: 687


[ July 08, 2003: Message edited by: Devesh H Rao ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Example of Reflexive composition relation.
 
Similar Threads
Q. equals and ==
Inner Class - UML Question
How will u swap three variable without using temp variable !??
Which is better is-a or has-a
How do we implement Composition and Aggregation relation in code ??