3

ternary association is structural relationship specifies that Object of one thing connected to object of other two's

I understand this relationship but I have no idea how to implement methods that shows association between these three classes.

lets consider following example

  • project has number of Developers who use particular programming language for development
  • developer use particular programming language for develop number of projects
  • in selected project one developer use only one programming language

ternary association between project ,developer and programming language

There exists a ternary association between these three classes.

I've read on different sources regarding this all across the internet and couldn't find a solution

How do I implement above scenario in code (in java) ?

P.S - Not only this Any other ternary association coding example would be appreciate

Sachithrra Dias
  • 185
  • 1
  • 2
  • 11
  • Other ternary association example: [UML ternary association](https://stackoverflow.com/q/46917458/5221149) – Andreas Nov 12 '18 at 20:32
  • 1
    @ThomasKilian: But the question "UML: how to implement Association class in Java" ***IS NOT*** really a duplicate because ternary associations are not the same as association classes! – Gerd Wagner Nov 16 '18 at 14:13
  • @GerdWagner The basics to implement both in a language are the same. The above is not really a ternary but a simple association class where `Language` is just an attribute of the AC. See the answer of @Andreas below. – qwerty_so Nov 16 '18 at 15:00
  • 2
    @ThomasKilian: I disagree. In the case of the ternary association above, there is no need to represent the association as a separate class. Instead, it can be simply represented/implemented by a complex-valued property like `developersByLanguage`in the `Project` class. The answer of @Andreas is not a good answer to the OP's question. Please reopen the question for giving me the opportunity to post a better answer :-) – Gerd Wagner Nov 16 '18 at 15:53
  • 1
    Hm. I guess I can't just re-open. There's a `reopen` button where you can vote. – qwerty_so Nov 16 '18 at 16:44
  • i cant reopen the question because view close votes" privilege in order to vote to reopen your own question. https://meta.stackexchange.com/questions/36415/how-do-you-reopen-a-closed-question – Sachithrra Dias Jan 09 '19 at 15:11
  • This question shall be reopneded: The duplicated question is about binary association. This is very different from a ternary association where there is not just an opposite end, but several opposite ends that have to be considered together. See also https://stackoverflow.com/q/71281673/3723423 – Christophe Feb 28 '22 at 19:08

2 Answers2

1

You could use one class to represent the "Project". This class has:

-Map <Developer, Langage> developers

One class to represent a "Developer". This class has:

-Set<Langage> langages

-Set<Projects> projects

Finally, one class to represent the "Language".

Class Project {
    Map<Developer, Language> developers = new HashMap<>();

    public void add(Developer developer) {
        developers.put(developer, developer.getLanguage());
        developer.registerOn(this);
    }

Class Developer {

    private Set<Language> languages;  
    private Set<Projects> projects;

    public boolean developIn(Language language) {
       return languages.contains(language);
    }

    public void registerOn(Project project) {
       projects.add(project);
    }
}

Enum Language {
    JAVA,
    PHP;
}
Jesus Zavarce
  • 1,729
  • 1
  • 17
  • 27
0

That UML diagram does not say what you believe it says. The association is an object too.

If you want to specify that "in selected project one developer use only one programming language", then the diagram should be:

enter image description here

Andreas
  • 154,647
  • 11
  • 152
  • 247
  • Why do you think that the ternary association model does not imply that "in a project one developer uses only one programming language"? – Gerd Wagner Nov 16 '18 at 14:08