0

My program has one public class followed by a constructor and 2 local classes (the inner classes have action events) called from a method. There is one additional static methods.

Public class

Constructor

local Classes

Methods

I am very confused to how the UML diagram would look for this. I have made one for a super class and subclasses before and it was straightforward enough, but i'm not sure how to include local classes and action events (like key listener).

Thank you for your help. I am new to java so go easy please.

Edit: I meant Class diagrams not all UML in general. Sorry.

0

2 Answers 2

1

A quick Google search yielded the following from http://www.sparxsystems.com/resources/uml2_tutorial/uml2_classdiagram.html:

Nestings A nesting is connector that shows the source element is nested within the target element. The following diagram shows the definition of an inner class, although in EA it is more usual to show them by their position in the project view hierarchy.

Inner class UML example
(source: sparxsystems.com)

0
0

UML defines 14 different types of diagrams. In the following I will assume you refer to the most common one: the Class Diagram.

Local classes have no inheritance relationship to the class they are defined in. However, each of their instances contain a reference to an instance of the class where they were defined. When you write new LocalClass() (which is the most usual), the referenced "parent" object is this. When you write aDefiningClassInstance.new LocalClass(), the referenced "parent" object is aDefiningClassInstance.

That clarified, the relationship of what you call the "public class" with the local classes is one of composition. Cardinality depends on you particular case, but it's most probably one-to-one with each local class.

Modern versions of UML introduce syntax for inner classes (which are practically the same as local ones), but IMHO this is excesively related to specific programming languages and does not represent the high-level relationships that UML is usually used for.

Whatever method calls the event handlers, it should belong to a class directly or indirectly storing references to them. Here you have two additional UML aggregation relationships (also of probable cardinality of one-to-one) if the calling method belongs to a class different to the defining one.

Not the answer you're looking for? Browse other questions tagged or ask your own question.