473,396 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Class association (in UML)

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 !
Feb 25 '07 #1
7 3121
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
Feb 25 '07 #2
"Oswaldfig" <Os*******@discussions.microsoft.coma écrit dans le message de
news: A3**********************************@microsoft.com...

| 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
Feb 25 '07 #3
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
Feb 26 '07 #4
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<OrderLineorderlines;
...
}

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

public class NewsGroup
{
private List<Postposts;
...
}

public class Post
{
private List<NewsGroupnewsgroups;
...
}

Arne
Feb 26 '07 #5
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<OrderLineorderlines;
...
}

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

public class NewsGroup
{
private List<Postposts;
...
}

public class Post
{
private List<NewsGroupnewsgroups;
...
}

Arne
Feb 26 '07 #6
Hi,

Joanna Carter [TeamB] wrote:
"Oswaldfig" <Os*******@discussions.microsoft.coma écrit dans le message de
news: A3**********************************@microsoft.com...

| 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
Feb 26 '07 #7
Hi,

Arne Vajhøj wrote:
>>Two examples:

order-(1)---------(0..*)-orderline
newsgroup-(1..*)-----------(0..*)-posts
Assuming all bidirectional:

public class Order
{
private List<OrderLineorderlines;
...
}

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<Postposts;
...
}

public class Post
{
private List<NewsGroupnewsgroups;
...
}
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
Feb 26 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Mon | last post by:
I am in the process of reorganizing my code and came across and I came across a problem, as described in the subject line of this posting. I have many classes that have instances of other classes...
4
UML
by: Ferryandi | last post by:
Hi, i want to ask is it possible to generate UML diagram from VS C#.NET? because i confuse on how to draw UML diagram that have User Interface. One more think to ask, is User Interface like for...
0
by: WideBoy | last post by:
Hi, I've been asked to create an XML namespace from a UML model diagram of a logical(hence, no PK FKs) relational database schema. I've read a lot of stuff on the web on how one might do this...
1
by: Frederik Vanderhaegen | last post by:
Hi, I'm a newbie in c# and have a simple question. How does you have to implement an association class (uml) in c#? Thanks in advance Frederik
0
by: mt | last post by:
Hi, I have vusual studio 2005, standard addition and I can create class UML diagrams uisng class designer (UML diagram of classes) for C# apps but not for C++ apps. Does anyone know whether...
1
by: mt | last post by:
Hi, I have vusual studio 2005, standard addition and I can create class UML diagrams uisng class designer (UML diagram of classes) for C# apps but not for C++ apps. Does anyone know whether...
24
by: not_a_commie | last post by:
If you were going to hire a software architect / functional lead for your project (written exclusively in C# including WPF, WCF) would you require that they have UML skills? Is being able to...
0
by: Ole | last post by:
In a class diagram it is possible to view a field as an association making it visible (with an arrow) that a class uses another class but what if I would like to make it visble that a class uses...
0
by: AlarV | last post by:
Hello again everyone! I'm creating a project in Java for a university lesson, by using UML Diagrams. To generally give you an idea of the project, I have to create a Property Office, that has as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.