UML Class Diagrams Class diagrams are among the centerpieces of the Unified Modeling Language. They are critical for helping you design classes that will serve as building blocks for your application. This article will cover the basics of class diagrams and help you see how you can use them in your software development?especially in building your business object classes. In this second article in the series, we take a close look at UML class diagrams. Class diagrams are most often used in the elaboration and construction phase of software projects. When used in conjunction with UML sequence diagrams (covered in the next article in this series), they can help you produce well-designed families of classes that form the foundation of flexible and extensible software applications. This article provides a practical overview of the most commonly used features of class diagrams. It is not intended to be a completely comprehensive guide to class diagrams?that would require a book; and, in fact, it's highly recommended that you refer to The Unified Modeling Language User Guide by Booch, Rumbaugh and Jacobson (Addison-Wesley) for the complete details on class diagrams. For the most up-to-date information, check out the latest official version of the UML specification at www.omg.org/technology/uml/index.htm. Why Use Class Diagrams? If you're creating monolithic applications where the application and data access logic is melded together inside the user interface, you will find little use for class diagrams?or the entire UML for that matter! Fortunately, many software developers are beginning to understand the importance of creating component-based applications that can be easily maintained, extended and scaled from the desktop to the Internet. This requires that you create families of classes (most importantly business object classes) that have crisp boundaries and a balanced distribution of responsibilities. Class diagrams can help immensely in this regard. They enable you to design your classes, which become the building blocks of your application. Class diagrams allow you to document the structure (attributes and operations) of classes. They are also extremely useful for understanding relationships between classes, inheritance hierarchies, and responsibilities of the entities that provide the system behavior. Modeling Class Structures As shown in Figure 1, classes are graphically represented as a rectangle containing three compartments. The upper compartment contains the name of the class, the middle compartment contains a list of attributes and the bottom compartment contains a list of operations.  Figure 1: You can choose to show or hide as much detail as you like in a class diagram, as shown in these two representations of the VSSItem class found in Microsoft's Visual Source Safe.You can display classes with as little or as much detail as desired. Figure 1 shows two different representations of Microsoft Visual SourceSafe's VSSItem class. The class on the left side shows a simpler representation of the class with just the attribute and operation names displayed. The class on the right side shows additional detail?the type and value of properties and the parameters (their types) and return values of operations. To the left of each attribute and operation is a symbol that indicates the item's visibility?public, protected, private or implementation (see the Visibility sidebar for details). When showing full detail, attribute names are followed by a colon and the type and default value of the attribute. Operation names are followed by parentheses. When showing full detail, the parentheses hold the argument name followed by a colon and the type and default value of the argument. A colon and the type of the operation's return value follow the parentheses. Modeling Class Relationships There are four different relationships that can be modeled in class diagrams?generalization, dependency, association and realization.  Figure 2: You can design a family of classes that inherit their interface from an abstract parent class. This model provides your applications with a great deal of flexibility and extensibility. | & | | 
By: Kevin McNeish
Kevin McNeish is President of Oak Leaf Enterprises, Inc, and chief architect of the MM .NET Application Framework. He is a Microsoft .NET MVP and a well-know INETA speaker and trainer throughout North America and Europe including VSLive!, DevTeach (where he serves as one of the .NET chairs), SDC Netherlands, and Advisor DevCon. He is co-author of the book Professional UML with Visual Studio .NET, author of the book .NET for Visual FoxPro Developers, writes articles and has been interviewed for .NET Rocks! He spends about half his time on the road training and mentoring companies to build well-designed, high-performance .NET applications.
kevinm@oakleafsd.com | Fast Facts | | Class diagrams are the most commonly used diagrams in the UML. They can make complex systems far easier to comprehend, analyze and design. | |
|