“Suppose we have implemented a scenario and we used aggregation in it, after some time we realize that use of aggregation is not a correct choice, now we want to use composition instead of aggregation. Can we replace composition with aggregation? At which phase(s) these changes are required? Justify your answer with solid reasons. ”
A concise, coherent and to the point comment is preferred over lengthy comment having irrelevant details. Your comment must not be more than 5-6 lines. Comments, posted on regular Lesson's MDB or sent through email will NOT be considered in any case. Any request about such an acceptance will not be catered.
jee nahi, we can not change composition with aggregation , these are two different concepts, in aggregation, the sub-part is independent of the whole part, while it is not the case in composition
If we want to change the aggregation relationship into composition then we have to put the object in the master class instead of reference
now i m gng to solve it with no ap log kro discus and thanx tariq bhai
Yar Ik New Home banalo ya Puranay barbaad shuda makan ko repair kr lo...... Dono sorto ma ap ko kaaam shoro sa shoro krna paray ga....! OK
SO Its better to make new........ SO answer is "NO"
Look at this given picture and analyzie your self...
in aggregation, object2 is outside of object 1 and in Composition object 2 is inside of Object 2.
and using aggregation information we can say that composition replaced aggregation and using composed objects of aggregation can exist indepandantly..
Aggregation is a specialize form of Association where all object have their own lifecycle but there is ownership and child object can not belongs to another parent object. Let’s take an example of Department and teacher. A single teacher can not belongs to multiple departments, but if we delete the department teacher object will not destroy. We can think about “has-a” relationship.
Composition is again specialize form of Aggregation and we can call this as a “death” relationship. It is a strong type of Aggregation. Child object dose not have their lifecycle and if parent object deletes all child object will also be deleted. Let’s take again an example of relationship between House and rooms. House can contain multiple rooms there is no independent life of room and any room can not belongs to two different house if we delete the house room will automatically delete. Let’s take another example relationship between Questions and options. Single questions can have multiple options and option can not belong to multiple questions. If we delete questions options will automatically delete
Time thoda hai dekha jaye ga aagay ALLAH ki marzi. me gng to post answer. ALLAH MALIK. Good Luck to all. ALLAH HAFIZ.
gud luck 2 u SilenT SouL
and thanx for sharing idea
Composition is implemented by creating object of one class in other class but in aggregation we just put then reference of a class in another by this if we destroy master class so then other class remain save. If we want to change the aggregation relationship into composition then we have to put the object in the master class instead of reference.
Just Taking Idea:
Both aggregation and composition are special kinds of associations. Aggregation is used to represent ownership or a whole/part relationship, and composition is used to represent an even stronger form of ownership. With composition, we get coincident lifetime of part with the whole. The composite object has sole responsibility for the disposition of its parts in terms of creation and destruction. In implementation terms, the composite is responsible for memory allocation and deallocation
Moreover, the multiplicity of the aggregate end may not exceed one; i.e., it is unshared. An object may be part of only one composite at a time. If the composite is destroyed, it must either destroy all its parts or else give responsibility for them to some other object. A composite object can be designed with the knowledge that no other object will destroy its parts.
Composition can be used to model by-value aggregation, which is semantically equivalent to an attribute. In fact, composition was originally called aggregation-by-value in an earlier UML draft, with “normal” aggregation being thought of as aggregation-by-reference. The definitions have changed slightly, but the general ideas still apply. The distinction between aggregation and composition is more of a design concept and is not usually relevant during analysis.
Finally, a word of warning on terminology. While UML uses the terms association, aggregation, and composition with specific meanings, some object-oriented authors use one or more of these terms with slightly different interpretations. For example, it is fairly common to see all three UML relationships grouped under a single term, say composition, and then to discuss object-oriented relationships as being either inheritance (generalization) or composition.
And an example for each situation :
a) Association is a relationship where all object have their own lifecycle and there is no owner. Let’s take an example of Teacher and Student. Multiple students can associate with a single teacher and single student can associate with multiple teachers, but there is no ownership between the objects and both have their own lifecycle. Both can create and delete independently.
b) Aggregation is a specialized form of Association where all object have their own lifecycle but there is ownership and child object can not belong to another parent object. Let’s take an example of Department and teacher. A single teacher can not belong to multiple departments, but if we delete the department, the teacher object will not be destroyed. We can think about “has-a” relationship.
Presentation main phases hain please check