Class diagrams are the most often used UML diagrams.
The purpose of a class diagram is to specify the structural makeup of the system.
This includes class relationships and the attributes and behaviors associated with each class.
Class diagrams are remarkable at illustrating inheritance and composite relationships.
To use class diagrams as an effective communication tool, developers must have a consistent
understanding of how the elements appearing on a class diagram are translated to Java.
This includes class relationships and the attributes and behaviors associated with each class.
Class diagrams are remarkable at illustrating inheritance and composite relationships.
To use class diagrams as an effective communication tool, developers must have a consistent
understanding of how the elements appearing on a class diagram are translated to Java.
Lets Detail it out :
The elements
The following items represent the elements of a class diagram and their corresponding representation in Java.
I will list the name of the element, followed by a short code snippet and a picture representing what
that element would look like on a class diagram.
that element would look like on a class diagram.
A short description of the element will conclude each section.
Class
A class (Figure A) is a blueprint for an object, containing three compartments.
The first represents the name of the class as defined in Java. The second represents the attributes.
The third compartment represents methods on the class.Attributes and operations can be preceded
with a visibility adornment.
with a visibility adornment.
A plus sign (+) indicates public visibility. A minus sign (-) denotes private visibility.
A pound sign (#) denotes protected visibility.
A pound sign (#) denotes protected visibility.
Omission of this visibility adornment denotes package-level visibility.
If an attribute or operation is underlined, this indicates that it is static.
If an attribute or operation is underlined, this indicates that it is static.
An operation may also list the parameters it accepts, as well as the return type,
as seen in the Java section in Figure A.
| Figure A |
Package
Packages (Figure B) are general-purpose grouping mechanisms. A package in UML translates directly into a package in Java. In Java, a package can contain other packages, classes, or both. When modeling, you'll typically have logical packages that serve primarily to organise your model. You'll also have physical packages that translate directly into Java packages within your system. Packages have a name that uniquely identifies the package.
| Figure B |
Lets understand more...