Wednesday, April 30, 2008

NetBeans 6.1, UML, and Attribute/Operation Visibility

NetBeans 6.1 supports three types of UML projects: platform-independent UML, Java-specific UML, and UML reversed engineered from Java code. In this blog entry, I'll briefly cover the differences between platform-independent UML and Java UML attribute and operation visibility for class diagrams in NetBeans. In a previous blog entry, I discussed the differences between these two types of UML in relation to placement of data types for attributes (members), operations (methods), and return values from operations/methods.

Platform-independent UML uses different notation to denote visibility than does Java-specific UML. While Java-specific UML uses the same keywords as Java code syntax itself (public, protected, private, and package), platform-independent UML instead uses + for public, - for private, # for protected, and ~ for package.

NetBeans makes attributes private by default in both forms of UML and makes operations public by default in both forms of UML. If the developer specifies a visibility for operations or attributes that is not recognized by NetBeans, NetBeans will make that operation or attribute package visibility in Java-specific UML and will mark such an operation or attribute with a ~ symbol in platform-independent UML.

The following two PNG files were exported from NetBeans using its "Export as Image" (CTRL+Shift+X) option. They show how NetBeans 6.1 treats attributes and operations of these various visibilities in Java-specific UML and platform-independent UML respectively.

Java-Specific UML

Note that NetBeans automatically creates a constructor for Java-specific classes and also automatically generates get/set accessor methods for all added attributes no matter the visibility of those attributes.



Platform-Independent UML

Note that no constructors or accessor methods are automatically created by NetBeans for platform-independent UML.

No comments: