1

I have a class which has an inner (nested) class. I have shown this relationship between the two classes in my class diagram. However, I am also using the inner class within the outer class... do I show another relationship for this or is the containment relationship enough?

asked May 5, 2015 at 15:45
2
  • What's the point of the inner class if another class outside of its parent is calling it? If other classes are calling your inner class you should make that inner class its own class because the parent of this class is not the only one who talks to it. Commented May 8, 2015 at 19:52
  • @Luminous sorry I meant to say that the inner class is being used in the outer class Commented May 8, 2015 at 19:56

2 Answers 2

2
+50

I would say no. You don't have to specify another relationship.

Inner classes AFAIK are implied to be used by their container. That's why they're an inner class. No one else needs to know about this class and no one has a use for it. This inner class is separate from it's containing object because it's different from the containing object, yet the container has an explicit need for this class and only this object has this need. Therefore, specifying a relationship between the containing class and inner class is enough to inherently imply these two classes are communicating with each other.

If the container class and inner class WEREN'T communicating with each other or worse yet, another object was calling directly to the inner class would show a clear design flaw of ever having this class as an inner class because its design purpose of being an inner class was not being correctly fulfilled.

If you wanted to go deeper in your design at some point you'd specify how the containing class is using the inner class and not just specify the container is using this inner class.

answered May 8, 2015 at 20:18
-2

From The Unified Modeling Language User Guide (Booch, Rumbaugh, Jacobson) association is "a structural relationship that describes a set of links, in which a link is a connection among objects".

Aggregation is "a special form of association that specifies a whole-part relationship between the aggregate (the whole) and a component (the part)."

Finally, usage is "a dependency in which one element (the client) requires the presence of another elements (the supplier) for its correct functioning or implementation."

Given that, aggregation implies usage, so it's not necessary to depict it separately for an inner class relationship.

answered May 8, 2015 at 21:39
1
  • 1
    An inner class is not an aggregate of the outer class, so your reasoning is formless. Commented May 8, 2015 at 21:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.