Composite and aggregation code example - is this correct

after reading all the aggregation and composition of this forum threads, i would like to know whether this is the corect understading in java implmentation of composite and aggregation.
example of aggregation
public class Money{}
public class Wallet {
private Money money;
public Wallet(Money money) {
this.money = money;
example of composite
public class Heart {}
public class Human {
private Heart heart;
private Human() {
heart = new Heart();
the aggregation implementation is based on the idea " The instance of aggregated class can be shared by many other classes. While those classes are deleted, the instance of aggreated class won't be deleted."
hence, i create money object outside the wallet, the passed the money into the wallet to make them "has a" relationship.
the composite implementation is based on the idea " the instance of composited class can only be used by one other class. While that class is deleted. The composited class will also be deleted."
hence, the creattion of heart is done by the human constructor it self.
1. is this the only ways to do the implementation for composite and aggregation?
2. is there other implementations for aggregation, the money class is constructed inside the wallet class?
3. is there other implementations for composition, the heart class is constructed outside the human class?
thank you very much!

Your abstractions are quite good.
1. is this the only ways to do the implementation for composite and aggregation?Broadly speaking yes, there are as some subtle variations, but you examples illustrate the key distinction.
2. is there other implementations for aggregation, the money class is constructed inside the wallet class?Yes, in practice you should also have methods to add and remove from an abstraction, so Wallet should have Wallet.add(Money) and Wallet.remove(Money) methods. You should also consider multiplicity, which may require that you use Qualified Classes and/or Associative Classes to implment an aggregation.
No, you should not construct the Money inside the Wallet. If you find you want to do this you should consider changing to a Composite.
3. is there other implementations for composition, the heart class is constructed outside the human class?Yes, it is usual to pass a this from the Composite (Human) to the part (Heart) when you construct it because Composition is implicitly a bi-directional relationship.
No the part of a composite should not be constructed outside the composite.

Similar Messages

  • Composition and Aggregation

    hey guys
    I have read the previous posts about composition and aggregation. And here is what i have got.
    Composition: life time of objects got to be the same. For example there is a composition between carframe and a car. If the car gets destroyed the carframe woulod also get destroyed.
    Aggregation: Life times of the objects are not the same, one oject can live even after the other object has been destroyed.
    But i seem to get all these things in theory, but when it comes to coding am not able to translate these theories. To be particular i would want someone to help with me how these relationship can be coded
    Thanks
    K

    Consider the following example :
    Car has an engine, chairs, wheel, etc. it is clear
    that this is composition, because "Car" is composed
    of engine, chairs wheel and so on. but think about
    what happens if you want to destroy the car, but
    reuse its engine, thing that frequently happen when
    you get your car smashed (didn't happen to be thanks
    god). Anyway you destroy the car, but it parts stay
    alive. so the "composed" objects lifetime can exceed
    the "composer" object lifetime.
    I think of composition and aggregation in the
    following way :
    if there is no meaning to the object without its
    parts (parts of which it is
    composed) then it is composition. if there is any
    meaning for the object without its parts (like empty
    paragraph (without words) in text, which can be left
    empty till the wrighter have something to write in)
    well, then it is aggregation.sometimes a car could be smashed and the engine would still be running, junkyard sells tires from wracked cars... all tha, however, has nothing to do with composition or aggration.
    composition is a strong form of ownership, a car probablly needs to have an engine, some tirs etc in order to be sold as a car, so the engin, tirs are usually composed as composition. life time of them begins when the car is instantiated and until the instance vanishes. when a car is smashed or totaled, it is merely a state of the car instnace, like a flat tire, the car instnace still exists, so a running engine on a totaled car is ok.
    usually if your object has a field referencing an object, that object is a composition, even the creation occurs earlier that the creation of the instance itself, such a case would be a DI: dependency injection. the destruction of an instance is a bit beyond the control of the composing instaance, that however dosnt matter, once the field loses the reference, we can think of it as the end of the life of the composed object. this is a bit different from C++ which allows you to invoke the destructor of the composed object. another difference is that you can have local objects, java objects all live in the heap area, no local objects.

  • Composition and aggregation implementation

    how to write composition and aggregation implementation in java ?
    As both of them contains another objects, how do we code to differentiate them ? I'm worried about implementation.
    Are they same in implementation-wise but differ in concept-wise ?

    user575089 wrote:
    how to write composition and aggregation implementation in java ?
    As both of them contains another objects, how do we code to differentiate them ? I'm worried about implementation.
    Are they same in implementation-wise but differ in concept-wise ?I really think you nailed it and there is nothing more for me to add.

  • Difference between composition and aggregation

    Could anyone explain to me the difference between aggregation and composition. I remember studying some but cant recall it.

    though this question has been put in for quite some time now but being of an interesting nature I would like to answer that still.
    As far as I know aggregation is a simple has a relationship
    e.g A student has books.
    A professor has students.
    Naome has a Car.
    Now you cannot say that : -
    A student is composed of books.
    However in composition the relationship is has a, is composed of .
    So A university is composed of many schools.
    A car is composed of parts.
    A housed is composed of windows.
    The second type of relationship is compositiob while first one is aggregation.

  • " Enhancing the Quality of ABAP Development ", downloadable code examples?

    Hello all,
    I just finished reading this book.  I would recommend it highly to experienced ABAP developers.  My only complaint is that the book did not give a link to the source code examples used in the book.
    Is anyone aware of any location where the source code examples in this book are stored?  I have checked both SAP  Press and Galileo Press's web sites.
    Thanks
    Bruce

    closing old post

  • LVOOP composition and delegates

    LVOOP doesn't support multiple inheritance, deciding instead to favour composition and aggregation (which happens to coincide with the "Gang of four" IIRC).
    When we are working with composition (An object contains sub-objects for some or all of its functionality) when do we start to talk about delegates?  At what stage does a sub-object of any of my given classes become a delegate?  Are there any guidelines as to what is a delegate and what not?
    If I have a Class A which exposes Methods 1,2,3,4 and 5 to the outside world I may choose to use Class B (or a derivative class) to implement Methods 3,4,and 5.  When does this class become a delegate?
    Shane.
    Say hello to my little friend.
    RFC 2323 FHE-Compliant

    Nickerbocker wrote:
    Could you explain more what about LVOOP not supporting multiple inheritance and why that is keeping you from accomplishing something?
    The way you describe delegation sounds right to me.  I do Composition and Delegation all the time in my LVOOP designs.  It is good to be on the same page when discussing what we call these patterns.  That being said, I read design pattern books to get my OOP juices flowing.  Not necessarily to look for exact solutions because they tend to be too generatlized to be directly applicable to a lot of real world problems.
    The lack of multiple inheritance is not keeping me from accomplishing anything at all.  I fully agree with AQ that anything which can be done with multiple inheritance can also be done with compositing.  I was just a little unclear as to when an object becones a delegate.
    Shane.
    Say hello to my little friend.
    RFC 2323 FHE-Compliant

  • Assembler code example to can application using 8051

    Hi,
    I am developing a CAN application using 8051 family microcontrollers. I need recognize the information coming through Rxdc pin. So far, I was not able to do this. Where can I get some assembler code example for this microcontroller? Someone has one ?
    Thanks.

    Hello-
    Unfortunately, we only provide source code for the NI-CAN boards in Windows under CVI and LabVIEW. The Philips site may have some examples. I believe that they actually sell a CAN chip that is integrated with an 8051.
    Randy Solomonson
    Application Engineer
    National Instruments

  • I erased my 2nd gen ipod touch, can it be restored, apple shop are saying no , some parts can not be downloaded. is this correct

    Sorry new to all this.
    I was re-selling my ipod touch 2nd generation so i erased all contents and setting ... was this correct ?
    The new owner is telling me she cant get it to work. she has taken it into the apple store and they have told her that parts that were erased ca no longer be downloaded.
    Is this correct ?
    Have i been an idiot ? lol

    That sounds correct.
    Many developers when they updated their apps to support iOS 5 and 6 dropped compatibility for iOS 4.2.1 and earlier.
    See the following for more easily  finding compatible apps
    iOSSearch - search the iTunes store for compatible apps.
    Vintapps 3.1.3 - paid app.
    Apple Club - filter apps by iOS version.

  • Problem with business place and section code in miro screen

    hi experts,
    i have done the following config. for validate the b/place and section code at the time of invoice and payment.
    in prerequisite-com.code=l001 and (posting key=31 or posting key=29 or posting key=21 
    in check-business place=1001 and section code=1001
    by this config. in t code fv60 and f-48 b/place and section code showing mandatory but in miro screen w/o b/place and section code system alowing to save the entry.
    please suggest me where i am wrong and what to do next?
    thanks and regards
    konishko

    hi
    i have written the condition as follows
    in prerequisite:bseg-bukrs=l001 and (bseg-bschl=31 or bseg-bschl=29 or bseg-bschl=21)
    in check:bseg-bupla=1001 and bseg-secco=1001
    by doing this in fv60 and f-48 screen is not allowing to post w/o b/place and section code but in miro screen system allow me to post w/o b/place . if i validate the miro screen then after giving the b/place it is not allowing me to post the same and giving the error message which i have created.
    how to solve this problem?
    please suggest me and please give me the steps.
    regards
    konishko

  • What is an Itunes  Gift Card and Certicates code?

    I have to make an account to get something in App-store, but when i have filled in the visa card information, its a question that says "Gift Cards and Certicates code" what is this?

    iTunes Store: Invalid, inactive, or illegible codes

  • I NEED MY UNBLOCKING CODE FOR MY IPHONE 4S ,I HAVE BEEN INCONTACT WITH MY SERVICE PROVIDER AND THEY CONFIRMED THEY HAVE SENT AN EMAIL TO YOURSELF TO GET THE CODE AND NOW I NEED TO CONTACT YOU MYSELF IS THIS CORRECT AS VODAFONE DO NOT SEEM TO BE HELPING ME

    I NEED MY UNBLOCKING CODE FOR MY IPHONE 4S ,I HAVE BEEN INCONTACT WITH MY SERVICE PROVIDER AND THEY CONFIRMED THEY HAVE SENT AN EMAIL TO YOURSELF TO GET THE CODE AND NOW I NEED TO CONTACT YOU MYSELF IS THIS CORRECT AS VODAFONE DO NOT SEEM TO BE HELPING ME

    There is no such thing as an unlock code for an iPhone. It's done by restoring the phone using iTunes

  • HT1918 revised credit card expiry date not updating on my account, warning box says card has expired even after i change the details and security code. anyone know how to correct this?

    has anyone experienced this i want to update my card details on my account but it says card expired even when i put in the new expiry date and security codes.

    Reset the device:
    Press and hold the Sleep/Wake button and the Home button together for at least ten seconds, until the Apple logo appears.
    Then edit your payment details.
    If that doesn't help, tap Settings > General > Reset > Reset All Settings. Then try again.
    iTunes Store: Changing account information
    iTunes Store: Accepted forms of payment

  • Facebook like button is not working, I have used the muse widget and created code from facebook. Does anyone know how to get this to work?

    Facebook like button is not working, I have used the muse widget and created code from facebook. Does anyone know how to get this to work?

    Hi connally25,
    Below is a link to a video tutorial on how to add a Facebook Log button, please check if you have followed the same steps to add the video.
    http://tv.adobe.com/watch/learn-adobe-muse-cc/adding-a-facebook-like-button/
    If you have followed the steps correctly and the button still does not work; here is a link to a forum thread which might help solving the issue:
    Facebook Follow Widget not working
    Regards
    Sonam

  • Firefox Sync setup says "Incorrect words, try again" after receiving message "Your answer was correct. Please copy and paste the text in this text box into the box below."

    When setting up Firefox Sync, I get all the way to the "Please Confirm You're Not a Robot" screen in the wizard, and enter the captcha values. I then receive in a small scrollable text area the message "Your answer was correct. Please copy and paste the text in this text box into the box below."
    I copy and paste the code, in this case "03AHJ_Vuv1gStVScBWSYWw6M4_KKQ4wzhCDSzKqiCfv57XXGyvHtOk4ixehysQhOTIf-lsL41lc5n-piztjYJSKu6urCeRvETVfpzRDh7OmHCDZiIBZv9Qg4oyrmWDMu6JA7Eh-4C8aZn4" into the only other visible text box, and click the next button, only to receive the message "Incorrect words, try again."
    My only option is to cancel at that point. I have tried this three times, once even starting the entire process over from the start, and it ends up with the same outcome each time.

    When setting up Firefox Sync, I get all the way to the "Please Confirm You're Not a Robot" screen in the wizard, and enter the captcha values. I then receive in a small scrollable text area the message "Your answer was correct. Please copy and paste the text in this text box into the box below."
    I copy and paste the code, in this case "03AHJ_Vuv1gStVScBWSYWw6M4_KKQ4wzhCDSzKqiCfv57XXGyvHtOk4ixehysQhOTIf-lsL41lc5n-piztjYJSKu6urCeRvETVfpzRDh7OmHCDZiIBZv9Qg4oyrmWDMu6JA7Eh-4C8aZn4" into the only other visible text box, and click the next button, only to receive the message "Incorrect words, try again."
    My only option is to cancel at that point. I have tried this three times, once even starting the entire process over from the start, and it ends up with the same outcome each time.

  • [code] does not work correctly, cannot post code example.

    Hi, I tried to do a code example, but HTML tags inside java quoted strings were intereperted. Like the <IMG> tag and the <H1> tag..
    How do I prevent this????
    Re: How to post an audio file in JSP or servlet

    OK, it was the IMG and H1 tags....
    Looks like I can embed an image though <img src="http://www.oracle.com/admin/images/ocom/oralogo_small.gif">

Maybe you are looking for

  • How to change the text of Terms and Condition of PO.

    I have given an task to add some text to the current TERMS and CONDITIONS (T&C) of a PO. Idea is to decrease the size of fonts also as after adding the new paragraph, the T&C itself will print on 2 pages. So decrease in font size is needed to fit the

  • Toolbars Hidden When Opening PDF's

    I am using Acrobat 8 Professional on Windows XP. Whenever I open any PDF, the toolbars are hidden. I can press F8 to get them back, but they are not visible by default. I once had this problem a few months ago and was able to fix it by deleting the p

  • Regarding  Block step type

    Hai experts, In the block there are  three kinds wahich are 1.Standard 2.Parforeach and 3.Foreach i want the details about all the three and where we use and when we use such block types.

  • Mail not responding.  App is open but will not quit or respond in any other way.

    My Mail app is not responding.  The Dock shows that Mail is open, but I cannot get the screen to pull up, quit or otherwise respond.  I tried to restart, but Mail stops that from happening.

  • [小讲坛]关于PSA table(2).

    各位好.. 又到了午后饭余,接着上次的话题,PSA..(不是标志汽车..更不是美国摄影协会..) 修复PSA的错,一般都会建议客户参考note 1150724.. 事实上这个note已经写得很详细了..或许也没啥必要赘述重复,就几个其中的重点请允许我提一下: 1. RSAR_PSA_PARTITION_CHECK 1) 用于 DDIC和DB table不整合时. 2) 只对 7.x 系统有效. 3) 关于遇到什么样的症状可以使用,请参考note的 Symptoms 部分. 4) 先不要用 rep