3

For example I hae a class Sensor a Class Control and a Class Rooksensor. I have an open arrow from Control to Sensor and a closed arrow from Rooksensor to Sensor. Here is what the UML-diagram looks like: uml A little guess I did was that in the class Rooksensor its like:

Rooksensor: Sensor

And in the class Sensor:

Control control1 = new Control();
Control control2 = new Control();

I only wanna know what the arrow mean, if anyone could give me a good explanation on what they mean and how I should implent it I would be really happy.

Preston Guillot
  • 6,493
  • 3
  • 30
  • 40
user3171107
  • 33
  • 1
  • 5
  • possible duplicate of [UML arrows/pointers explanation](http://stackoverflow.com/questions/1874049/uml-arrows-pointers-explanation) – metacubed Feb 05 '15 at 17:14

1 Answers1

5

The "Closed" arrow is inheritance. Rooksensor derives from Sensor, so it has the inheritance arrow to it.

The "Open" arrow is association. This just indicates that Control knows about Sensor. It knows about it because one of its methods takes one as a parameter.

Your last bit of code (where Sensor creates some Controls) doesn't really mesh with the diagram. If Sensor holds onto Control objects it has an aggregation/composition relationship with it that isn't shown in your diagram.

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
  • Thanks for the explanation. So I actually have to do: Sensor sensor1 = new Sensor(); and Sensor sensor2 = new Sensor(); because it makes 2 sensors? – user3171107 Feb 05 '15 at 17:19
  • @user3171107 The multiplicity on that association just indicates how many times it is referenced. *You shouldn't be instantiating them at all* by the diagram. If you instantiate, you almost automatically have an aggregation/composition relationship, not simple association. – BradleyDotNET Feb 05 '15 at 17:21
  • I'd use aggregation only in abstract domain modeling, not when it comes to classes. For code classes associations are pretty fine. You could adorn them with the roles. But that is just a different rendering to having an attribute of the target class type. It might increase readability. Again YMMV – qwerty_so Feb 05 '15 at 18:15