Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. The Lounge
  3. Composition??

Composition??

Scheduled Pinned Locked Moved The Lounge
tutorialquestion
39 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L led mike

    I believe the section of that wikipedia page on Aggregation covers the topic very clearly and correctly. But of course you would have to read it to know that wouldn't you now?

    Germyan wrote:

    You don't have an answer do you??

    I know I have an answer to the problem called Germyan. I won't read any more of your messages. X|

    led mike

    G Offline
    G Offline
    Germyan
    wrote on last edited by
    #25

    :laugh: :laugh: :laugh: I am sorry, if I did something wrong here.. but I know most people don't know the concepts they play with on day to day basis. Just thought to play on it.

    led mike wrote:

    problem called Germyan.

    :laugh: - creative one G.

    L 1 Reply Last reply
    0
    • G Germyan

      you are missing a important one.. when a composition is destroyed, are the objects belonging to it be destroyed as well? If the answer is NO then it is AGGREGATION. G.

      S Offline
      S Offline
      Shog9 0
      wrote on last edited by
      #26

      Germyan wrote:

      you are missing a important one.. when a composition is destroyed, are the objects belonging to it be destroyed as well? If the answer is NO then it is AGGREGATION.

      AFAIK, there's a little bit more to it than that... but i'll bite: where in the example that i gave you did i imply that any part of my composite collection type would not be destroyed along with the collection? Granted, i did not explicitly state that it wouldn't leave bits and pieces of itself orphaned and scattered all over Creation... but i didn't think it was necessary to state such an obvious requirement.

      G N 2 Replies Last reply
      0
      • S Shog9 0

        Germyan wrote:

        you are missing a important one.. when a composition is destroyed, are the objects belonging to it be destroyed as well? If the answer is NO then it is AGGREGATION.

        AFAIK, there's a little bit more to it than that... but i'll bite: where in the example that i gave you did i imply that any part of my composite collection type would not be destroyed along with the collection? Granted, i did not explicitly state that it wouldn't leave bits and pieces of itself orphaned and scattered all over Creation... but i didn't think it was necessary to state such an obvious requirement.

        G Offline
        G Offline
        Germyan
        wrote on last edited by
        #27

        I think you said that it is a objects collection.. inside the collection you will have objects, They used a famous example to explain composition.. house vs room, can the room exist without a house?? NO Can the object exist without a collection?? YES.. so your example is not composition. I mean there are many areas, where your example violate the original definition of the composition. But, I do agree that it is the closest example, I get so far. G.

        S 1 Reply Last reply
        0
        • G Germyan

          I think you said that it is a objects collection.. inside the collection you will have objects, They used a famous example to explain composition.. house vs room, can the room exist without a house?? NO Can the object exist without a collection?? YES.. so your example is not composition. I mean there are many areas, where your example violate the original definition of the composition. But, I do agree that it is the closest example, I get so far. G.

          S Offline
          S Offline
          Shog9 0
          wrote on last edited by
          #28

          Germyan wrote:

          I think you said that it is a objects collection.. inside the collection you will have objects,

          Ah, i get it. You thought i was describing the composition as being the storage of objects within the collection. But those aren't really part of the type itself, rather the type is defined as being able to store objects. The type itself is composed of an array and a tree. Those types make up the composition. They exist for the purpose of allowing the collection to fulfill its purpose; their definitions and lifetimes are tied to it.

          N G 2 Replies Last reply
          0
          • G Germyan

            Is this your answer.. don't shoot off target... the question is a simple one.. your answer and the one who gave a 5 for your reply, both can be considered given poor answers :) G.

            L Offline
            L Offline
            Liam OHagan
            wrote on last edited by
            #29

            No, your question was poorly worded and vague.

            I have no blog...

            1 Reply Last reply
            0
            • G Germyan

              :laugh: :laugh: :laugh: I am sorry, if I did something wrong here.. but I know most people don't know the concepts they play with on day to day basis. Just thought to play on it.

              led mike wrote:

              problem called Germyan.

              :laugh: - creative one G.

              L Offline
              L Offline
              led mike
              wrote on last edited by
              #30

              Germyan wrote:

              I am sorry, if I did something wrong here.

              Ok, fair enough, it's a native english thing but don't use the word "poor" to describe peoples attempts to help you. They are freely giving you their time so even if you don't agree you should not make derogatory statements about their reply. The word "poor" is definitely negative in the english language.

              led mike

              G 1 Reply Last reply
              0
              • S Shog9 0

                Germyan wrote:

                you are missing a important one.. when a composition is destroyed, are the objects belonging to it be destroyed as well? If the answer is NO then it is AGGREGATION.

                AFAIK, there's a little bit more to it than that... but i'll bite: where in the example that i gave you did i imply that any part of my composite collection type would not be destroyed along with the collection? Granted, i did not explicitly state that it wouldn't leave bits and pieces of itself orphaned and scattered all over Creation... but i didn't think it was necessary to state such an obvious requirement.

                N Offline
                N Offline
                Nirosh
                wrote on last edited by
                #31

                I think both .Net and Java uses the composite relation, when define their collection classes. In that sense, the answer given here is correct. At least according to the book, but if you are against it, then,,, may be it is a good question for, who invented composition :cool:

                L.W.C. Nirosh. Colombo, Sri Lanka.

                S 1 Reply Last reply
                0
                • S Shog9 0

                  Germyan wrote:

                  I think you said that it is a objects collection.. inside the collection you will have objects,

                  Ah, i get it. You thought i was describing the composition as being the storage of objects within the collection. But those aren't really part of the type itself, rather the type is defined as being able to store objects. The type itself is composed of an array and a tree. Those types make up the composition. They exist for the purpose of allowing the collection to fulfill its purpose; their definitions and lifetimes are tied to it.

                  N Offline
                  N Offline
                  Nirosh
                  wrote on last edited by
                  #32

                  Yes!! you are right, you get my 5

                  L.W.C. Nirosh. Colombo, Sri Lanka.

                  1 Reply Last reply
                  0
                  • S Shog9 0

                    Germyan wrote:

                    I think you said that it is a objects collection.. inside the collection you will have objects,

                    Ah, i get it. You thought i was describing the composition as being the storage of objects within the collection. But those aren't really part of the type itself, rather the type is defined as being able to store objects. The type itself is composed of an array and a tree. Those types make up the composition. They exist for the purpose of allowing the collection to fulfill its purpose; their definitions and lifetimes are tied to it.

                    G Offline
                    G Offline
                    Germyan
                    wrote on last edited by
                    #33

                    Okay, I Accept it! thank for having this discussion thread. It is late here (11.00 PM) I am going to sleep now.. G.

                    1 Reply Last reply
                    0
                    • N Nirosh

                      I think both .Net and Java uses the composite relation, when define their collection classes. In that sense, the answer given here is correct. At least according to the book, but if you are against it, then,,, may be it is a good question for, who invented composition :cool:

                      L.W.C. Nirosh. Colombo, Sri Lanka.

                      S Offline
                      S Offline
                      Shog9 0
                      wrote on last edited by
                      #34

                      To be perfectly honest, i don't think it is particularly useful to draw a strong distinction here. But, if it helps you to think of your designs in these terms, then more power to you. :)

                      N 1 Reply Last reply
                      0
                      • L led mike

                        Germyan wrote:

                        I am sorry, if I did something wrong here.

                        Ok, fair enough, it's a native english thing but don't use the word "poor" to describe peoples attempts to help you. They are freely giving you their time so even if you don't agree you should not make derogatory statements about their reply. The word "poor" is definitely negative in the english language.

                        led mike

                        G Offline
                        G Offline
                        Germyan
                        wrote on last edited by
                        #35

                        Accepted!! Thanks G.

                        1 Reply Last reply
                        0
                        • S Shog9 0

                          To be perfectly honest, i don't think it is particularly useful to draw a strong distinction here. But, if it helps you to think of your designs in these terms, then more power to you. :)

                          N Offline
                          N Offline
                          Nirosh
                          wrote on last edited by
                          #36

                          I am with you here.. I was replying to your message, but it went to the one above.

                          Shog9 wrote:

                          To be perfectly honest, i don't think it is particularly useful to draw a strong distinction

                          okay, then the million dollar question is.. why you have a concept called composition?

                          L.W.C. Nirosh. Colombo, Sri Lanka.

                          S 1 Reply Last reply
                          0
                          • N Nirosh

                            I am with you here.. I was replying to your message, but it went to the one above.

                            Shog9 wrote:

                            To be perfectly honest, i don't think it is particularly useful to draw a strong distinction

                            okay, then the million dollar question is.. why you have a concept called composition?

                            L.W.C. Nirosh. Colombo, Sri Lanka.

                            S Offline
                            S Offline
                            Shog9 0
                            wrote on last edited by
                            #37

                            Nirosh wrote:

                            okay, then the million dollar question is.. why you have a concept called composition?

                            Beats me. Why do some people spend their days coming up with names for any basic concepts? Why are there "canonical" lists of "fundamental OOP concepts" (see Ennis Ray's thread above this one)? Why are label-makers still so popular? Why does my wife keep moving the drain stopper into a basket under the sink? These are the great mysteries of The Universe, my friend. Things mortal men were not meant to understand. ;)

                            1 Reply Last reply
                            0
                            • L Lost User

                              class car { }; class red { }; class RedCar : public red, public car { };

                              N Offline
                              N Offline
                              Nirosh
                              wrote on last edited by
                              #38

                              Much better example would be... public class RedCar { private class car { }; private class red { }; };

                              L.W.C. Nirosh. Colombo, Sri Lanka.

                              1 Reply Last reply
                              0
                              • E Ennis Ray Lynch Jr

                                http://en.wikipedia.org/wiki/Object_composition[^]

                                Need a C# Consultant? I'm available.
                                Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

                                N Offline
                                N Offline
                                Nirosh
                                wrote on last edited by
                                #39

                                IMHO the example can easily confused the user, since it does not tell much about the definition of the Carburetor. I think, to make it complete, you need to have the Carburetor defined (as private) inside the Car class. // Composition class Car { private: Carburetor* itsCarb; public: Car() {itsCarb=new Carburetor();} virtual ~Car() {delete itsCarb;} }; // Composition [Corrected] class Car { private class Carburetor {} private: Carburetor* itsCarb; public: Car() {itsCarb=new Carburetor();} virtual ~Car() {delete itsCarb;} };

                                L.W.C. Nirosh. Colombo, Sri Lanka.

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups