1

My question is, how can I implement this?

Exam * ____________ 1 Student
            |
            |
          Mark

I search a lot by the Internet but I didn't find any clear answer about the way that I can implement an association class.

Pigueiras
  • 18,778
  • 10
  • 64
  • 87
  • 1
    Well, you listed 3 different programming languages, and UML for who knows why. Pick a language, and know for sure that each of the 3 you mentioned has a built-in mechanism for associate classes. Look harder. – drdwilcox Nov 16 '11 at 19:23
  • 1
    I put 3 different languages because I don't mind the language of the implementation, I only want to know how to implement it. – Pigueiras Nov 16 '11 at 19:25
  • 2
    do you really mean that an Exam is taken only by one Student? Shouldn't the multiplicity next to Student be *? – beluchin Dec 09 '11 at 13:12

3 Answers3

4

Generally, a class that points to two other class instances. It is often used to implement a many-to-many relationship between object types.

In C#:

public class Product
{
    public string Name;
}

public class Department
{
    public string Name;
}

// An association class
public class ProductDepartment
{
    public Product Product;
    public Department Department;
}
harpo
  • 41,820
  • 13
  • 96
  • 131
  • That's when the multiplicity is 1-1, isn't it? What happen when the multiplicity is 1-*? – Pigueiras Nov 16 '11 at 19:27
  • Then you don't need an association class, as you can just put a list of references to the "*" class ("Exam") in the "1" class ("Student"). – harpo Nov 16 '11 at 19:29
  • Could it be this then? Student 1 - * Exam 0...1 - 1 Mark? – Pigueiras Nov 16 '11 at 19:42
  • @harpo in Student 1 ---- * Exam scenario why not putting student reference in Exam class? So we have just single Student instance reference in each Exam object rather list of Exam instance in one Student object, What is difference? Besides that, what about many to many relation? Student * ---- * Exam ? Which class should take reference to another? – QMaster May 03 '18 at 22:52
0

Please read the following for Many-to-Many relationship. Entity Framework: Duplicate Records in Many-to-Many relationship

Please read the following for (0..1 to Many) https://codereview.stackexchange.com/questions/14077/is-it-proper-tpt-inheritance

Community
  • 1
  • 1
LCJ
  • 22,196
  • 67
  • 260
  • 418
0

As Pigueiras said: 'Could it be this then? Student 1 - * Exam 0...1 - 1 Mark?' then 1-1 relationship does not also need 'a class that points to two other class instances' as harpo said

thoitbk
  • 269
  • 2
  • 9
  • 21