Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Mapping

Reply
Thread Tools

Mapping

 
 
Jennifer Jazz
Guest
Posts: n/a
 
      05-02-2007
My question is regarding the mapping of Class diagram to the C++
coding.

There are 3 realtions in Class diagram

1) Assosication
2) Composition
3) Aggregation (Weak Composition).

-----------------------------------------------------
Class diagram for A ----- B (Association)
I handle it coding like that

main() {
A objA;
B objB;

objA.funA(objB); // or
objB.funB(objA);
}

-----------------------------------------------------
A <>---- B (filled diamond) for compoistion
Take the example of CAR and ENGINE, this relation is composition

I handle it coding like that

class B {
}
class A {
B objB; //or B* objB
}

This shows when A's Object destroys B also destroys.
Im clear with above two concepts but when aggregation comes.

A <>---- B (non-filled diamond) for agregation
Take the example of CAR and WHEEL-CUP.

class B {
}
class A {
B* ptrB;
}



Take the example of CAR and WHEEL-CUP, this relation is aggregation.
CAR changes its wheel-cup each time when it go to service the car.

CAR <>------ Wheel-CUp

im not getting one thing thing when car destroyed (i.e. destructor
called) does Wheel-Cup should also destroy? iF yes then the difference
between COMPOSITION and AGGREGATION is only left that in aggregation
the aggregated object (B* ptrB) points to different objects i.e.
different wheel cups at different states. and in COMPOSITION it only
keep points to only one object. AND in both aggre. and comp. object B
destoys as object A destroys.

One more question , in composition the Object B is created as object A
is created i.e. (When CAR is created ENGINE also created) but what abt
wheel cups? when they will be created and destroyed? as wheel cups
can live independly and when car goes for services, they new wheel
cups only points of the this car showing new wheel cups attached. So
the other wheel cups destroyed !!??

I shall be very very thankful if u answer me this question

 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      05-02-2007
On May 2, 2:23 pm, Jennifer Jazz <Jeniffer...@gmail.com> wrote:
> My question is regarding the mapping of Class diagram to the C++
> coding.
>
> There are 3 realtions in Class diagram
>
> 1) Assosication
> 2) Composition
> 3) Aggregation (Weak Composition).
>
> -----------------------------------------------------
> Class diagram for A ----- B (Association)
> I handle it coding like that
>
> main() {
> A objA;
> B objB;
>
> objA.funA(objB); // or
> objB.funB(objA);
>
> }
>
> -----------------------------------------------------
> A <>---- B (filled diamond) for compoistion
> Take the example of CAR and ENGINE, this relation is composition
>
> I handle it coding like that
>
> class B {}
>
> class A {
> B objB; //or B* objB
>
> }
>
> This shows when A's Object destroys B also destroys.
> Im clear with above two concepts but when aggregation comes.
>
> A <>---- B (non-filled diamond) for agregation
> Take the example of CAR and WHEEL-CUP.
>
> class B {}
>
> class A {
> B* ptrB;
>
> }
>
> Take the example of CAR and WHEEL-CUP, this relation is aggregation.
> CAR changes its wheel-cup each time when it go to service the car.
>
> CAR <>------ Wheel-CUp
>
> im not getting one thing thing when car destroyed (i.e. destructor
> called) does Wheel-Cup should also destroy? iF yes then the difference
> between COMPOSITION and AGGREGATION is only left that in aggregation
> the aggregated object (B* ptrB) points to different objects i.e.
> different wheel cups at different states. and in COMPOSITION it only
> keep points to only one object. AND in both aggre. and comp. object B
> destoys as object A destroys.
>
> One more question , in composition the Object B is created as object A
> is created i.e. (When CAR is created ENGINE also created) but what abt
> wheel cups? when they will be created and destroyed? as wheel cups
> can live independly and when car goes for services, they new wheel
> cups only points of the this car showing new wheel cups attached. So
> the other wheel cups destroyed !!??
>
> I shall be very very thankful if u answer me this question


This is more of a UML question (the C++ syntax is only incidental) and
should be asked on comp.object or similar. See this FAQ for what is on-
topic here:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

<OT>My recollection is that composition implies that one class owns
the other entirely, whereas aggregation implies that one class holds a
reference to another but isn't its owner. If that is accurate, then a
better analogy would be a car which holds references for each of the
people/pets/whatever that it is carrying. It doesn't own them and they
shouldn't necessarily be destroyed when it is, but the car may need to
access their methods/properties (e.g., to get their weight for vehicle
dynamics or some such).</OT>

Cheers! --M

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"not enough server storage" error when mapping drive =?Utf-8?B?bXV6eg==?= Wireless Networking 1 08-05-2005 03:00 AM
Waiting for Wireless before mapping drives =?Utf-8?B?anBtd2l6YXJk?= Wireless Networking 1 04-26-2005 04:11 PM
Problem mapping some folders? =?Utf-8?B?QXN5bHVt?= Wireless Networking 1 03-26-2005 04:40 PM
Mapping a local folder Rick Donnellon Wireless Networking 1 01-11-2005 12:32 AM
XP, Novell and Losing Mapping =?Utf-8?B?RGo=?= Wireless Networking 0 08-18-2004 12:43 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57