gpuguy
gpuguy

Reputation: 4585

UML: guideline for visibility

I am reading Real Time UML: Advances in the UML for Real-Time Systems (3rd Edition) 3rd Edition by Bruce Powel Douglass

In section 10.5 when talking about guidlines on detailed design on visibility. he says:

Only make semantically appropriate operations visible.

This guideline seeks to avoid pathological coupling among classes. For example, suppose a class is using a container class. Should the operations be GetLeft() and GetRight() or Prev() and Next()? The first pair makes the implementation visible (binary tree) while the latter pair captures the essential semantics (ordered list).

I am unable to understand what he is trying to say here and especially last line.

Can someone elaborate his point ?

Upvotes: 0

Views: 81

Answers (1)

qwerty_so
qwerty_so

Reputation: 36333

Well, it's a bit subtile. GetLeft and -Right have the directions in their name which are derived from an internal implementation as binary tree. So the internal data structure is sort of visible in the interface. And that should not be the case. It is better to keep this knowledge inside for several reasons. First, the outer world must not care how things are implemented. Second, if you decide to implement it in a different way (e.g. via a ring buffer) the GetRight would be odd from an internal view if you reach the right border of the buffer. Prev and Next clearly target the business/outer usage aspect of the operations.

Upvotes: 2

Related Questions