Reputation: 123
Let's say we have three classes A, B
and C
, and an instance a
(resp. b
/c
) of type A
(resp. B
/C
).
Suppose that b
is an attribute of a
and c
is an attribute of b
.
In a method of a
, the following is called : b.c.operation()
How can we represent this in a sequence diagram ?
Upvotes: 2
Views: 1164
Reputation: 11892
Is this something you are looking for? You can try it out at https://www.zenuml.com.
Upvotes: 1
Reputation:
In programming it is not good to have b.c.operation()
All data should be hidden (should be private) in the class.
But if we have b.c.operation()
, in the compiler it changes to (b.c).operation()
so your code is equal to this code:
t=b.c;
t.operation();
Upvotes: 1
Reputation: 455
According to the Law of Demeter, an object should only communicate directly with its own neighbours. So in your case, a should not be calling b.c.operation() at all, as c is not a's neighbour. Rather, class B should provide an interface for this purpose, such as
doCOperation(){c.operation();}
and this is what a should call.
So the sequence of operations beocomes:
b.doCOperation()
c.Operation()
within doCOperation()
and returns the result to a.Have a go at the sequence diagram now and it should be much easier.
Upvotes: 4