PC Review


Reply
Thread Tools Rate Thread

Class association (in UML)

 
 
=?Utf-8?B?T3N3YWxkZmln?=
Guest
Posts: n/a
 
      25th Feb 2007
Hi there,
I'm a newbie in C# and i am looking for a simple yet clearly code example
of an association between two classes (a multiciplity association for
example) to help me understand a bit more of UML.

[class1] <- 0..1 --------- 0..* -> [class2]

Thanks !
 
Reply With Quote
 
 
 
 
Joanna Carter [TeamB]
Guest
Posts: n/a
 
      25th Feb 2007
"Oswaldfig" <(E-Mail Removed)> a écrit dans le message de
news: A3F60F01-21B5-428D-B1E8-(E-Mail Removed)...

| I'm a newbie in C# and i am looking for a simple yet clearly code
example
| of an association between two classes (a multiciplity association for
| example) to help me understand a bit more of UML.
|
| [class1] <- 0..1 --------- 0..* -> [class2]

The ordinality of this example relationship is not really very useful. It
states that 0 or 1 instances of class1 can be related to 0 or more instances
of class2.

IMO, it would be more normal to fix the class1 end at 1 and then you have a
classic one-to-many relationship; whereas, if you change class 2 to have an
ordinality of 1..*, then you have a "lookup" relationship where an optional
class1 can be related to any number of class2.

Having 0 in either end signifies optionality, 1 signifies "compulsarity".

HTH

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer


 
Reply With Quote
 
=?UTF-8?B?QXJuZSBWYWpow7hq?=
Guest
Posts: n/a
 
      25th Feb 2007
Oswaldfig wrote:
> I'm a newbie in C# and i am looking for a simple yet clearly code example
> of an association between two classes (a multiciplity association for
> example) to help me understand a bit more of UML.
>
> [class1] <- 0..1 --------- 0..* -> [class2]


Two examples:

order-(1)---------(0..*)-orderline
newsgroup-(1..*)-----------(0..*)-posts

Arne
 
Reply With Quote
 
=?Utf-8?B?T3N3YWxkZmln?=
Guest
Posts: n/a
 
      25th Feb 2007
Thanks Joanna, Arne for your comments, perhaps you can show me an example
written C# ? It helps me understand i guess how UML deals with this.

"Arne Vajhøj" wrote:

> Oswaldfig wrote:
> > I'm a newbie in C# and i am looking for a simple yet clearly code example
> > of an association between two classes (a multiciplity association for
> > example) to help me understand a bit more of UML.
> >
> > [class1] <- 0..1 --------- 0..* -> [class2]

>
> Two examples:
>
> order-(1)---------(0..*)-orderline
> newsgroup-(1..*)-----------(0..*)-posts
>
> Arne
>

 
Reply With Quote
 
=?UTF-8?B?QXJuZSBWYWpow7hq?=
Guest
Posts: n/a
 
      26th Feb 2007
Oswaldfig wrote:
> "Arne Vajhøj" wrote:
>> Oswaldfig wrote:
>>> I'm a newbie in C# and i am looking for a simple yet clearly code example
>>> of an association between two classes (a multiciplity association for
>>> example) to help me understand a bit more of UML.
>>>
>>> [class1] <- 0..1 --------- 0..* -> [class2]

>> Two examples:
>>
>> order-(1)---------(0..*)-orderline
>> newsgroup-(1..*)-----------(0..*)-posts

> Thanks Joanna, Arne for your comments, perhaps you can show me an

example
> written C# ? It helps me understand i guess how UML deals with this.


Assuming all bidirectional:

public class Order
{
private List<OrderLine> orderlines;
...
}

public class OrderLine
{
private Order order;
...
}

public class NewsGroup
{
private List<Post> posts;
...
}

public class Post
{
private List<NewsGroup> newsgroups;
...
}

Arne
 
Reply With Quote
 
=?Utf-8?B?T3N3YWxkZmln?=
Guest
Posts: n/a
 
      26th Feb 2007
Thanks Arne,

Your example is very helpfull !

OswaldFig

"Arne Vajhøj" wrote:

> Oswaldfig wrote:
> > "Arne Vajhøj" wrote:
> >> Oswaldfig wrote:
> >>> I'm a newbie in C# and i am looking for a simple yet clearly code example
> >>> of an association between two classes (a multiciplity association for
> >>> example) to help me understand a bit more of UML.
> >>>
> >>> [class1] <- 0..1 --------- 0..* -> [class2]
> >> Two examples:
> >>
> >> order-(1)---------(0..*)-orderline
> >> newsgroup-(1..*)-----------(0..*)-posts

> > Thanks Joanna, Arne for your comments, perhaps you can show me an

> example
> > written C# ? It helps me understand i guess how UML deals with this.

>
> Assuming all bidirectional:
>
> public class Order
> {
> private List<OrderLine> orderlines;
> ...
> }
>
> public class OrderLine
> {
> private Order order;
> ...
> }
>
> public class NewsGroup
> {
> private List<Post> posts;
> ...
> }
>
> public class Post
> {
> private List<NewsGroup> newsgroups;
> ...
> }
>
> Arne
>

 
Reply With Quote
 
Laurent Bugnion [MVP]
Guest
Posts: n/a
 
      26th Feb 2007
Hi,

Joanna Carter [TeamB] wrote:
> "Oswaldfig" <(E-Mail Removed)> a écrit dans le message de
> news: A3F60F01-21B5-428D-B1E8-(E-Mail Removed)...
>
> | I'm a newbie in C# and i am looking for a simple yet clearly code
> example
> | of an association between two classes (a multiciplity association for
> | example) to help me understand a bit more of UML.
> |
> | [class1] <- 0..1 --------- 0..* -> [class2]
>
> The ordinality of this example relationship is not really very useful. It
> states that 0 or 1 instances of class1 can be related to 0 or more instances
> of class2.
>
> IMO, it would be more normal to fix the class1 end at 1 and then you have a
> classic one-to-many relationship;


I can imagine that a 0..1 ---> 0..* relationship makes sense in certain
scenarios. For example in ASP.NET, we have custom controls which are
basically classes. Sometimes you can use a custom control for the
included functionality without including it in a Page. In that case, you
need to check if the control has a Parent. So you have the following
relationship:

[Page] 0..1 ------- 0..* [CustomControl]

> whereas, if you change class 2 to have an
> ordinality of 1..*, then you have a "lookup" relationship where an optional
> class1 can be related to any number of class2.
>
> Having 0 in either end signifies optionality, 1 signifies "compulsarity".


Actually having 0 on one end signifies "forbiddenity" ;-) but I can't
really think of a practical example... "0..1" specifies optionality.

> HTH
>
> Joanna


Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 
Reply With Quote
 
Laurent Bugnion [MVP]
Guest
Posts: n/a
 
      26th Feb 2007
Hi,

Arne Vajhøj wrote:

>>> Two examples:
>>>
>>> order-(1)---------(0..*)-orderline
>>> newsgroup-(1..*)-----------(0..*)-posts


> Assuming all bidirectional:
>
> public class Order
> {
> private List<OrderLine> orderlines;
> ...
> }
>
> public class OrderLine
> {
> private Order order;
> ...
> }


As an add-on, the "1" relationship specifies that the "order" variable
may not be null. It specifies that the class OrderLine may not have a
life of its own, but that it is always attached to an Order. Translated
in code, it means you may use the "order" variable without checking if
it's null.

If you had had a "0..1" relationship, then the "order" variable may be
null and you need to check that in the code before using it.

> public class NewsGroup
> {
> private List<Post> posts;
> ...
> }
>
> public class Post
> {
> private List<NewsGroup> newsgroups;
> ...
> }


Again, the "1..* relationship means that posts are always attached to at
least one newsgroup. So the "newsgroups" list is never empty.

> Arne


Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
how to create an association in set association control panel crazygirl Windows Vista Mail 8 5th Aug 2010 01:11 PM
Static class association in class diagram? Ole Microsoft C# .NET 0 10th Nov 2008 10:04 AM
Linq DataContext Designer:Association to a derived class? Richard Collette Microsoft C# .NET 4 11th Mar 2008 03:30 PM
File Association - unable to force association =?Utf-8?B?RGF2aWRN?= Windows XP General 4 30th Jun 2007 11:30 AM
Implementing association class Frederik Vanderhaegen Microsoft C# .NET 1 26th Feb 2006 12:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:16 AM.