• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Composition in Cam's Book

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

On page 140 of Cam's study guide(2nd Ed.)there's an example UML diagram of composition and then a written explanation of how it's implemented in Java, but no actual example in java. Could someone post an code example based on this UML diagram? Thanks. (I understand composition in at the UML level but need to see this particular example in actual Java syntax)

Brian
 
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, UML is pretty near the implementation but here is my take on p140, in a very simple eample (the UML doesnt specify any access modifers or return types so I made all the methods default and the instance variable.




The main pont I think here is just to show the UML representation of Composition. The code doesnt really show more than the basic Association and Navigation (the getQuestion() Method). To represent composition in the code the constructor for the Question class would need a reference to an exam object or something similar to show that the lifecycle of the question(s) is dependent on an exam object.
[ October 26, 2008: Message edited by: Stephen Davies ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic