1

I'm try to think how I can understand this UML diagram and check how I can represent it to code:

enter image description here

What is make me confuse, we have an association relation between Company and Employee interface, and Designer classe is implement the Employee interface, but how we can connect Company with Employee interface?

What I understand (PHP for Example):

class Company { ... } class GameDevCompany extends Company { ... } class Designer extends GameDevCompany implements Employee { ... } 

If I think about this diagram like this code, its a truth way or I missing something or make something wrong?

Thanks

6
  • What is an Airbort? And which language are you using in that code snippet? Commented Apr 29, 2021 at 16:54
  • The code snippet just to preview code(pseudo), any language its not important, I need to understand the principle... Airport is an super class which need to manage company has plans in airport... ========== I will edit question to add a new image from specific book Commented Apr 29, 2021 at 17:00
  • Well, every language is different. And you are using keywords defined in some language. How these keywords map is language specific. Also I was concerned about your type Airbort which I assumed to be airport but that was not knowing. Would be nice to fix that in the UML and the code. That exra image is not needed. Commented Apr 29, 2021 at 17:05
  • Nice to know, Thank you! I will :tup: Commented Apr 29, 2021 at 17:08
  • Thank you for nice feedback, I update my to make sure its clear base on your recommendation, thank you Commented Apr 29, 2021 at 17:15

2 Answers 2

2

We have three concepts in this diagram:

  • Specialization: a Company has two specializations which are GameDev Company and Outsourcing Company
  • Realization: an interface Employee can be realized by any class that implements this interface, such as Designer (or Programmer, Artist, Tester, ...)
  • Association: a Company is associated with Employee. The diagram does not say anything about multiplicity. But since this is a very simple model, and based on our knowledge, we could guess that a Company may be associated with no, one, or several Employee.

In PHP terminology, specialization is inheritance, which is expressed with the extend keyword:

class Company { ... } class GameDevCompany extends Company { ... } 

In PHP terminology interfaces are implemented rather than realized and this is expressed with keyword implements

interface Employee { ... } class Designer implements Employee { ... } 

The association from one Company with potentially several Employee requires that Company has some kind of iterable container such as an array that holds references to the Employee objects. My PHP is very rusty, but I understand that objects in an array are always references which is exactly what is needed for ordinary associations.

Sign up to request clarification or add additional context in comments.

Comments

1

I just brushed up my rusted PHP knowledge and all I can say now is that your code is just fine. extends is inheritance (so the generalization relation to the left) and implements is interface implementation (so the realize relation to the right).

To extend on your query regarding the association: well, my PHP is very rusted, but IIRC it's completely untyped. So you will have some object pointer, say $employee in the Company class defined and that references objects having implemented the Employee interface. So you would probably do some $employee->doWork() in the Company class implementation. Likely you would not have a single one but an array. Honestly, that's really too long ago with the syntax. But you would probably know how to code that.

P.S. Since (as said) my PHP is very rusted I'm not so in the depth that I would know what the combination of extends and implements would produce.

5 Comments

Thank you for answer and for your time!, what about the associations relation between the Company and Interface, in our code, we need to add any something or specific code or its not needed since the relational is already done via Designer, this is meaning the arrow between Company and Interface?
Sorry, if my PHP knowledge is even rustier. But doesn't class Designer extends GameDevCompany implements Employee mean that a Designer is a specialization of GameDevCompany and a realization of Employee? This does not seem to correspond to the diagram in which Designer is just a realization of Employee that is associated with a GameDevCompany...
@Christophe Honestly, your PHP isn't that rusted as mine. I was not looking in such depth but just saw the use of extends and implements. Maybe you can place an answer....
@qwerty_so thanks for this invitation :-) Always happy to refresh a little bit my own memory ;-)
Really thank you all, Also I would like to add something, after reading more and more, I see this diagram build to represent the Factory Method Pattern, so, if we think like the factory method pattern we will find the answer like your explain in both answers, and the main idea for association if we use factory method pattern via access implemented method via realization or specialization, I think this example is very useful too: refactoring.guru/design-patterns/factory-method/php/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.