UML
  1. UML (4 messages)

    Hi, Tried lot to understand,but no luck. Can anyone provide Java code example from which it can be clear between the Association,Composition and Aggregation relation.UML concept is ok but cant find suitable Java code example to tell this difference. Thanks in Advance

    Threaded Messages (4)

  2. Example[ Go to top ]

    Hi Tanuja, Let me try to put in examples here in my words of wisdom. This is how I try to correlate Association : Lets consider 2 classes "A" & "B". There are 3 different ways these 2 objects of these classes can interact with each other. 1) By creating the instance of A in B with in the method scope. 2) Vice versa of B and A 3) Be passing the object of A to B method as a parameter. Aggreation : Whole-Part relationship If you have a object being created within the scope of a constructor of a class. As long as the main object is alive the object being created in constructor would also be alive. both the objects can also be created independently Composition : Strong form of whole part relationship. Restricted access based Inner class of a outer class. Inner class is part and which cannot reside outside of Whole (outer class) Hope this helps :-) regards, Satish Bobburi
  3. Re: Example[ Go to top ]

    Hi Satish, Thanks for the example. But still I am having some doubts when showing the relations in the UML.If class A is holding an instance varible of Class B and executes the method of class B is this is Dependancey relation or association relation. In what type of code do we show normally a Composition and dependancy(Uses) relation. Thanks Tanuja
  4. Question corrected[ Go to top ]

    Hi Satish, Please ignore the previous q as there was some typo in last line. Thanks for the example. But still I am having some doubts when showing the relations in the UML.If class A is holding an instance varible of Class B and executes the method of class B is this is Dependancey relation or association relation. In what type of code do we show normally a "Association" and dependancy(Uses) relation. Thanks Tanuja
  5. Aggregation vs. Composition[ Go to top ]

    An aggregate relationship relates two objects that can exist independent of the relationship, whereas a composite relationship relates two objects that must exist together (or, where the "child" object cannot exist without the parent). This is defined by your domain. You cannot formally model this in Java, because any object can technically exist on its own, even if it shouldn't according to your business rules. Consider a database of Work Experience for, say, a College Alumni database. Suppose you have a Person and an Employer. Employer has an aggregate relationship to Person, since either can exist without the other; an Employer might have no people employed, and a Person might not have a job. Further, consider that Person has an Address. Person has a composite relationship with address, as an Address has no meaning on its own (at least in this hypotehtical application). The Java code, however, could implement this in a number of ways, none of which will enforce these rules at the class level. These can be enforced at the database level, to a certain degree, using things like "CASCADE ON DELETE" at the like.