www.vustudents.ning.com

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

# GDB Solution Of CS304 date 14 feb to 15 feb 2013 plz post your ideas HERE

“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.

Views: 7188

### Replies to This Discussion

i shall reply you if anyone give me or post solution s

Our main purpose here discussion not just Solution

We are here with you hands in hands to facilitate your learning and do not appreciate the idea of copying or replicating solutions.

Composition

Composition is about expressing relationships between objects. Think about the chair example. A chair has a Seat. A chair has a back. And a chair has a set of legs. The phrase "has a" implies a relationship where the chair owns, or at minimum, uses, another object. It is this "has a" relationship which is the basis for composition.

Consider the class definitions for each of the chair parts and the chair itself below. Note that for simplicity, each of the chair parts is just an empty object. They would each have properties and methods of their own in a real application.

package chairs.parts {
public class Seat {
public function Seat() {}
}
}

package chairs.parts {
public class Back {
public function Back() {}
}
}

package chairs.parts {
public class Leg {
public function Leg() {}
}
}

package chairs {
import chairs.parts.Back;
import chairs.parts.Leg;

public class Chair {

protected var back:Back;
protected var seat:Seat;
protected var legs:Array;

public function Chair() {
back = new Back();
seat = new Seat();

legs = new Array();
legs.push( new Leg() );
legs.push( new Leg() );
legs.push( new Leg() );
legs.push( new Leg() );

}
}
}
In this example, the Chair object itself is composed of an instance of the Back class, an instance of the Seat class and 4 instances of the Leg class. Each of those objects has its own responsibilities but they are related together in a composition referred to as Chair .

Using composition does not mean you will never use inheritance. In fact, when you begin composing a new object, you will frequently still need to choose an appropriate super class. Supposing that you wanted to create an OfficeChair class, you might start by extending Chair and then adding an additional component which allows the seat to swivel freely. It would be appropriate to say the OfficeChair is a Chair but it has a swivel.

package chairs.parts {
public class Swivel {
public function Swivel() {}
}
}
package chairs {
import chairs.parts.Swivel;

public class OfficeChair extends Chair {
protected var swivel:Swivel;

public function OfficeChair() {
super();
swivel = new Swivel();
}
}
}
In the code above you are visibly using both inheritance and composition to create a new object. This is the most common way you will work when building complex objects.

Aggregation

There is a closely related concept to composition called aggregation. In conversation the differences between composition and aggregation are often ignored. However, for the sake of accuracy, it will be covered here.

Just like composition, aggregation occurs when an object is composed of multiple objects. However, with composition, the internal objects (such as Leg , Seat and Back ) are owned by the main object ( Chair ). If you destroy the Chair , you also likely want the Leg , Seat and Back instances destroyed because they are a composition which, together, form a single Chair .

However, imagine you make a new type of Chair called DinnerChair . DinnerChair extends Chair but it also defines a property which refers to the person currently sitting in the DinnerChair . You could say that DinnerChair has a Person .

The Chair instance certainly doesn't own the Person and you probably shouldn't assume that the Person is destroyed if the Chair is destroyed. Further, the Person exists independent of the Chair . The Person can leave this chair and sit on another one. This independence makes a great deal of difference so this combination of objects is referred to as an aggregation instead of composition. When designing your applications, it is important to note that difference.

Usually, when using composition, the object instantiates the objects it has. Look at the Chair class above. You can see that Back , Seat , and Leg are instantiated in the Chair class. When using aggregation, the object does not instantiate the objects it has. Look at the code below. The DinnerChair class has a Person , but it does not instantiate Person .

package humans {
public class Person {
public function Person() {}
}
}
package chairs {
import humans.Person;

public class DinnerChair extends Chair {

public var person:Person;

public function DinnerChair() {
super();
}
}
}

Aggregation
Aggregation is a specialize form of Association where all object have their own lifecycle but there is ownership and child object cannot belongs to another parent object. Let’s take an example of Department and teacher. A single teacher cannot belong to multiple departments, but if we delete the department, teacher object will not destroy. We can think about “has-a” relationship.
Points:
• Specialize form of Association.
• has-a relationship between objects
• Object have independent life-cycles
• Parent-Child relationship

Composition
Composition is again specialize form of Aggregation. It is a strong type of Aggregation. Child object does not have their lifecycle and if parent object deletes all child objects 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 cannot 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.
Points:
• Specialize form of Aggregation
• Strong Type of Aggregation.
• Parent-Child relationship
• only parent object has independent life-cycle.

sir i have simple question plz tell me in yes / not

Can we replace composition with aggregation?

yes we can replace composition with aggergation

Can n e body tell me in which phase we can replace them??

Can we replace composition with aggregation?

kisi ko ye ni laga k is question me kuch mistake ha???

first we implemented the scenario with aggregation, then after we want to do it with composition.... what is being replaced? composition or aggregation?

i think it should be as Can we replace aggregation with composition?

already exited things are replaced with new things...

or am i wrong?

yes bro you are wrong

Q thik hai ap aisay hi confuse ho rahe ho

already exited things are replaced with new things...

ek player out ho to new player aa ke usy replace kerta ha ya jo out howa us ne aney wale player ko replace kiya? :D :P

question yeh hai k kia hum aggregation ki jagah composition use ker sacty hain.

the answer is yes we can replace.

and 2nd question is in which phase(s) these changes can be made. (it implies that answer to the first question is yes)

now answer to question 2, as the we have implemented a scenario therefore at 2 phases where these changes have to be made, eik to coding phase hai aur dosra app sab khud search ker lain

1

2

3

4

5

## VIP Member Badge & Others

------------------------------------

## Latest Activity

Umair posted a status
3 minutes ago
Fatima replied to Fatima's discussion eco403 assignment solution 2 in the group ECO403 Macroeconomics
32 minutes ago
vu student updated their profile
33 minutes ago

### Jannah ? Hold you deen tight.

1 hour ago
2 hours ago
3 hours ago
Muhammad Bilal replied to BBA(6th smes)'s discussion assignment 1 spring 2021 in the group MGT402 Cost & Management Accounting
4 hours ago
★---★ ⱮԱϚҠȺហ ȺచȺហ ★---★ updated their profile
4 hours ago