• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

UML example

Hi there. Can you please give me a simple programming example of Generalization, Aggregation, Composition, Association (are there any more???)

for example I think (?) this is an example of composition:
====
composition:
Class1{
     private class2
}

- class1 is composed of class2
- denoted as a filled diamond and a solid line.
- Class1 <#>------ Class2
====

Thanks a million
0
DamienL
Asked:
DamienL
  • 3
  • 2
1 Solution
 
sasapopovicCommented:
There are a lot of good articles about this. You can google your query and will get a lot of good matches.
Here are some:
http://www.codeproject.com/gen/design/idclass.asp
http://www.johndeacon.net/UML/UML_Appendix/Generated/UML_Appendix_structural.asp

I hope this is what you need.
0
 
DamienLAuthor Commented:
yea i have actually visited loads of websites about this and they confuse me. It's difficult to get simple examples (in my opinion anyway)

For example just something simple like:
If Class1 has Class2 as a private member then this is composition (?)
If Class2 is passed into Class1 as a parameter then this is aggregation (?)

What about Association, etc?

and what is the difference between a broken line and a non-broken line as in:
http://www.dofactory.com/Patterns/PatternIterator.aspx

0
 
InteractiveMindCommented:
> If Class1 has Class2 as a private member then this is composition
I don't think that it has to be private.

> If Class2 is passed into Class1 as a parameter then this is aggregation
It's an example of aggregation, yea.

> and what is the difference between a broken line and a non-broken line
The dashed lines normally represent the life of the object.


> i have actually visited loads of websites about this and they confuse me
> ..
> What about Association, etc?

I found the online stuff pretty poor and hard going as well. So, I got myself down to my local library, and found a book on it, and gave it a quick read, and found it _much_ easier.

I really recommend you getting your hands on a _book_ rather than relying on this online stuff..


Good luck.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
InteractiveMindCommented:
> The dashed lines normally represent the life of the object.
But when it has an arrow head, it depicts the return message.
0
 
DamienLAuthor Commented:
Hi InteractiveMind,

You say:
> If Class2 is passed into Class1 as a parameter then this is aggregation
It's an example of aggregation, yea.
- Can you give me another example please?

> and what is the difference between a broken line and a non-broken line
The dashed lines normally represent the life of the object.
- You mean the life of one class might depend on another, can you please explaine?

Thanks a lot
0
 
InteractiveMindCommented:
> Can you give me another example please?

If the class "has" (or "contains") an object, then it's an example of aggregation. So, Composition is a specific case of Aggregation. The difference though between composition and aggregation, is that whilst composition is an example of aggregation, the objects that compose the 'parent' object are destroyed when the parent object is. However, a class may simply store a _reference_ to an object, in which case, if it's destroyed, then only the reference is destroyed - and not the object itself.


> You mean the life of one class might depend on another, can you please explaine?

Yes exactly; this is related to aggregation really.
Like with composition, if an object is destroyed, then any sub-objects are also destroyed; so the sub-objects lifetime is dependent it's parents..

Furthermore, an object may be destroyed when a particular function is executed. In this case, the object's lifetime is dependent on that function (and therefore, the "actions" of that function's class).
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now