Welcome!

Cloud Expo Authors: Yeshim Deniz, Hovhannes Avoyan, Elizabeth White, Liz McMillan, Pat Romanski

Related Topics: .NET

.NET: Article

The UML Class Diagram

The UML Class Diagram

The class diagram is an excellent aid to model the attributes, operations, and associations of the classes in your applications. This article, the second in a series of articles that introduce the reader to the concepts of object-oriented design and the Unified Modeling Language, focuses on UML class diagrams. It reviews UML class diagramming notation and the use of Visio to construct a class diagram.

The Need for Modeling Classes
Class structures are fundamental to any object-oriented programming language. The class structure is a template for the objects that will implement the functionality of your applications. As a .NET developer, you need to become increasingly familiar with the classes available in the .NET Framework. As you gain experience developing .NET applications you will discover the need to develop your own class libraries. Good design of object-oriented applications dictates a clear separation of functionality between the user interface, business logic, and data access logic. Well-designed applications achieve this separation of functionality through the development of class libraries that encapsulate internal processing. By developing class libraries, your applications become more manageable, scalable, and extendable.

An all-too-common problem in many object-oriented applications is a lack of preplanning. Class libraries evolve haphazardly. As a result, the distinction of roles and responsibilities among the various classes in the library becomes muddled and convoluted. These class libraries are difficult to manage, revise, and employ. This is especially problematic when large teams of developers build an application. Employing a tool to model your class libraries is imperative to ensure that the application remains consistent, manageable, and clearly defined. A UML class diagram is an excellent tool for modeling the structure of your class libraries.

Modeling Class Structure Using UML
In a UML class diagram, a rectangle divided into three parts represents the class. The top section contains the name of the class, the middle section contains the attributes of the class, and the lower section contains the operations performed by the class. Operations may take the form of methods, constructors, destructors, properties, or events. Figure 1 illustrates a UML class diagram representing a loan class. This class is part of a library loan application that tracks loan, member, and inventory information for a small library.

Examining the class diagram reveals that along with the name of the attribute, it defines the attribute's accessibility. A minus sign (-) in front of the attribute name indicates it is private. A plus sign (+) indicates it is public, and a pound sign (#) indicates it is protected. A private element is only accessible from within the class. A public element is accessible from any code in the same project or any project with a reference to the project containing the class. A protected element is accessible from within the class and any class derived from the class.

Although the UML specifications do not define specific data types, when developing classes for use in .NET assemblies you can strongly type the attributes using the supported types of your implementation language. Visio allows the choice of either VB, C#, C++, or IDL supported data types. Data types can also be complex data types defined by your class library or the .NET class library. For example, a catalog class may have an item attribute that is of type System.Data.DataRow. Another possible scenario would be to create a catalog class as a collection class whose item attribute is an Item class type.

The lower section of the UML class shape defines the operations of the class. Typically, the class diagram will define the name of the operation, its accessibility, any parameters passed in to the operation, and any return value passed back when the operation executes. The loan class represented in Figure 1 contains two constructors (Sub New), a function (CalculateDueDate), an event procedure (OverDueNotice), and a property (LoanID). Unfortunately, the UML specifications do not define a way to identify the various operation types in the diagram. You can, however, add your own notation to indicate the various types depending on the modeling tool you use. Figure 2 shows the loan class shape with custom stereotypes added to identify the various operations defined in the diagram.

Modeling Class Associations
When a class refers to or uses another class, the classes form an association. For example, in the library loan application we have identified the need to construct a Loan class and a Book class. The responsibility of the Loan class is to maintain information about a book out on loan. This includes the member who has the book, the book, and the due date. The responsibility of the Book class is to maintain relevant information about the book. This includes ISBN, title, author, and publisher. Since the Loan class maintains a reference to the Book class, the book class is a collaborator of the Loan class. A line connecting the two classes represents this association in the class diagram. The association line often includes a label to describe the association.

Association lines can also indicate the direction of the association. In the previous case, the Loan class maintains a reference to the Book class, but the book class does not maintain a reference to the Loan class. To depict a one-way association, you add an arrow to the association line. The class diagram shown in Figure 3 documents the association between the loan class and the book class.

Sometimes a single instance of one class associates with multiple instances of another class. For example, a member may have multiple books out on loan. In this case, a single instance of a member class is associated with multiple instances of the Loan class. Multiplicity is included in the class diagram by placing the appropriate symbol on the association line. The class diagram in Figure 4 indicates that an instance of the Member class may be associated with multiple instances of the Loan class.

Using Visio to Construct a Class Diagram
Now that you're familiar with some of the notations used to construct a class diagram, you are ready to investigate the use of Visio to create class diagrams. If you do not have Visio installed, you can still benefit from following along and completing the diagram with paper and pencil.
1.   Start up Visio. From the File menu choose New -> Software -> UML Model Diagram.
2.   Locate the Shapes window along the left side of the screen. This window includes a tab for the common UML diagrams. Select the UML Static Structure tab (see Figure 5).
3.   From the Shapes window click and drag the Class shape onto the design surface. Right-click the Class shape on the design surface and choose Properties. A UML Class Properties window becomes visible (see Figure 6). Change the name to "Book" and add the description "Responsible for maintaining book information" in the Documentation text box.
4.   Select Attributes on the Categories list box in the left side of the window. Click on the New button on the right side of the window to add a new attribute to the class. Click on the Properties button to display the UML Attribute Properties window. Change the name of the attribute to "mISBN". Change the type to "VB::Char" and verify that the visibility is "private". Click the OK button to return to the UML Class Properties window.
5.   Select Operations in the Categories list box on the left side of the window. Click on the New button on the right side of the window to add a new operation to the class. Click on the Properties button to display the UML Operation Properties window. Change the name of the operation to "ISBN". Change the return type to "VB::Char" and verify that the visibility is "public". Select "Code Generation Options" in the Categories list box on the left side of the window. Change the operation kind to "Property" and check the "Create Get Method" and "Create Set Method" check boxes to indicate it is a readable/writable property. Click the OK button to return to the UML Class Properties window.
6.   Select Operations in the Categories list box on the left side of the window. Click on the New button on the left side of the window to add a new operation to the class. Click on the Properties button to display the UML Operation Properties window. Change the name of the operation to "CheckAvailability". Change the return type to "VB::Boolean" and verify that the visibility is "public". Select "Parameters" in the Categories list box on the left side of the window. Click on the New button on the right side of the window to add a new parameter to the operation. Click on the Properties button to display the UML Parameter Properties window. Change the name of the parameter to "ReservationDate" and the type to "VB::Date". Click the OK button to return to the UML Operation Properties window. Click the OK button to return to the UML Class Properties window. Click OK to close the UML Class Properties window. The Book class diagram should look similar to the one shown in Figure 7.
7.   In order to demonstrate the creation of class associations, add a Member class and a Loan class to the class diagram. If you want some practice, add some attributes and operations to these classes.
8.   From the Shapes window, click and drag the Binary Association shape onto the design surface. Attach end 1 of the Binary Association to the Member class and end 2 to the Loan class. The Binary Association line will turn red if it is not attached properly. Right-click the Binary Association shape on the design surface and choose Properties. The UML Association Properties window will display. Change the name of the association to "Takes Out". Change the Name Reading Direction to "forward". Change End 1's multiplicity to 1 and check the IsNavigable check box. When you are finished, click OK to close the window.
9.   Right-click the "Takes Out" Binary Association shape on the design surface and choose Shape Display Options. The UML Shape Display Options window displays. Under the General section, click the Name check box. Under the Suppress section, click on the First end and Second end check boxes. When finished, click OK.
10.   Figure 8 shows the completed diagram, including an association between the Loan class and the Book class. For additional practice, add this association to your diagram.

Conclusion
This article has introduced you to using the Unified Modeling Language to model the class structure of your application. The class diagram is a great aid for modeling the attributes and operations of the classes that make up your application. The class diagram also shows how the various classes in your application associate with each other. A CASE tool such as Visio, although not necessary, is beneficial in the creation of the class diagram.

A future article will continue the study of UML and class associations, focusing on modeling class inheritance hierarchies. In addition, you will be introduced to modeling interfaces, meta classes, and utility classes, which are all commonly used in class library applications. Finally, you will experience using Visio to generate a Visual Studio .NET class library from the UML model.

More Stories By Dan Clark

Dan is a Microsoft Certified Trainer, Microsoft Certified Solution Developer, and a Microsoft Certified Database Administrator. For the past seven years he has been developing applications and training others how to develop applications using Microsoft technologies. Dan has been developing and training Microsoft's .NET technologies since the early betas. He has recently authored the book "An Introduction to Object-Oriented Programming with Visual Basic .NET," published by Apress.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Cloud Expo Latest Stories
With the explosion of the cloud, more businesses are transitioning to a recurring revenue model to generate reliable sales, grow profits, and open new markets. This opportunity requires businesses to get to market quickly with the pricing and packaging options customers want. In addition, you will want to take advantage of the ensuing tidal wave of data to more effectively upsell, cross-sell and manage your customers. All of this is possible, but only with the right approach. At 15th Cloud Expo, Brendan O'Brien, Co-founder at Aria Systems and the inventor of cloud billing panelists, will lead a panel discussion on what it takes to launch and manage a successful recurring revenue business. The panelists will offer their insights about what each department will need to consider, from financial management to line of business and IT. The panelists will also offer examples from their success in recurring revenue with companies such as Audi, Constant Contact, Experian, Pitney-Bowes, Teleko...
Planning scalable environments isn't terribly difficult, but it does require a change of perspective. In his session at 15th Cloud Expo, Phil Jackson, Development Community Advocate for SoftLayer, will broaden your views to think on an Internet scale by dissecting a video publishing application built with The SoftLayer Platform, Message Queuing, Object Storage, and Drupal. By examining a scalable modular application build that can handle unpredictable traffic, attendees will able to grow your development arsenal and pick up a few strategies to apply to your own projects.
Come learn about what you need to consider when moving your data to the cloud. In her session at 15th Cloud Expo, Skyla Loomis, a Program Director of Cloudant Development at Cloudant, will discuss the security, performance, and operational implications of keeping your data on premise, moving it to the cloud, or taking a hybrid approach. She will use real customer examples to illustrate the tradeoffs, key decision points, and how to be successful with a cloud or hybrid cloud solution.
The cloud provides an easy onramp to building and deploying Big Data solutions. Transitioning from initial deployment to large-scale, highly performant operations may not be as easy. In his session at 15th Cloud Expo, Harold Hannon, Sr. Software Architect at SoftLayer, will discuss the benefits, weaknesses, and performance characteristics of public and bare metal cloud deployments that can help you make the right decisions.
Over the last few years the healthcare ecosystem has revolved around innovations in Electronic Health Record (HER) based systems. This evolution has helped us achieve much desired interoperability. Now the focus is shifting to other equally important aspects – scalability and performance. While applying cloud computing environments to the EHR systems, a special consideration needs to be given to the cloud enablement of Veterans Health Information Systems and Technology Architecture (VistA), i.e., the largest single medical system in the United States.
Cloud and Big Data present unique dilemmas: embracing the benefits of these new technologies while maintaining the security of your organization’s assets. When an outside party owns, controls and manages your infrastructure and computational resources, how can you be assured that sensitive data remains private and secure? How do you best protect data in mixed use cloud and big data infrastructure sets? Can you still satisfy the full range of reporting, compliance and regulatory requirements? In his session at 15th Cloud Expo, Derek Tumulak, Vice President of Product Management at Vormetric, will discuss how to address data security in cloud and Big Data environments so that your organization isn’t next week’s data breach headline.
Scott Jenson leads a project called The Physical Web within the Chrome team at Google. Project members are working to take the scalability and openness of the web and use it to talk to the exponentially exploding range of smart devices. Nearly every company today working on the IoT comes up with the same basic solution: use my server and you'll be fine. But if we really believe there will be trillions of these devices, that just can't scale. We need a system that is open a scalable and by using the URL as a basic building block, we open this up and get the same resilience that the web enjoys.
Is your organization struggling to deal with skyrocketing volumes of digital assets? The amount of data is growing exponentially and organizations are having a hard time managing this growth. In his session at 15th Cloud Expo, Amar Kapadia, Senior Director of Open Cloud Strategy at Seagate, will walk through the essential considerations when developing a cloud storage strategy. In this discussion, you will understand the challenges IT is facing, why companies need to move to cloud, and how the right cloud model can help your business economically overcome the data struggle.
If cloud computing benefits are so clear, why have so few enterprises migrated their mission-critical apps? The answer is often inertia and FUD. No one ever got fired for not moving to the cloud – not yet. In his session at 15th Cloud Expo, Michael Hoch, SVP, Cloud Advisory Service at Virtustream, will discuss the six key steps to justify and execute your MCA cloud migration.
The 16th International Cloud Expo announces that its Call for Papers is now open. 16th International Cloud Expo, to be held June 9–11, 2015, at the Javits Center in New York City brings together Cloud Computing, APM, APIs, Security, Big Data, Internet of Things, DevOps and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportunity. Submit your speaking proposal today!
Most of today’s hardware manufacturers are building servers with at least one SATA Port, but not every systems engineer utilizes them. This is considered a loss in the game of maximizing potential storage space in a fixed unit. The SATADOM Series was created by Innodisk as a high-performance, small form factor boot drive with low power consumption to be plugged into the unused SATA port on your server board as an alternative to hard drive or USB boot-up. Built for 1U systems, this powerful device is smaller than a one dollar coin, and frees up otherwise dead space on your motherboard. To meet the requirements of tomorrow’s cloud hardware, Innodisk invested internal R&D resources to develop our SATA III series of products. The SATA III SATADOM boasts 500/180MBs R/W Speeds respectively, or double R/W Speed of SATA II products.
In today's application economy, enterprise organizations realize that it's their applications that are the heart and soul of their business. If their application users have a bad experience, their revenue and reputation are at stake. In his session at 15th Cloud Expo, Anand Akela, Senior Director of Product Marketing for Application Performance Management at CA Technologies, will discuss how a user-centric Application Performance Management solution can help inspire your users with every application transaction.
SYS-CON Events announced today that Gridstore™, the leader in software-defined storage (SDS) purpose-built for Windows Servers and Hyper-V, will exhibit at SYS-CON's 15th International Cloud Expo®, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Gridstore™ is the leader in software-defined storage purpose built for virtualization that is designed to accelerate applications in virtualized environments. Using its patented Server-Side Virtual Controller™ Technology (SVCT) to eliminate the I/O blender effect and accelerate applications Gridstore delivers vmOptimized™ Storage that self-optimizes to each application or VM across both virtual and physical environments. Leveraging a grid architecture, Gridstore delivers the first end-to-end storage QoS to ensure the most important App or VM performance is never compromised. The storage grid, that uses Gridstore’s performance optimized nodes or capacity optimized nodes, starts with as few a...
SYS-CON Events announced today that Cloudian, Inc., the leading provider of hybrid cloud storage solutions, has been named “Bronze Sponsor” of SYS-CON's 15th International Cloud Expo®, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Cloudian is a Foster City, Calif.-based software company specializing in cloud storage. Cloudian HyperStore® is an S3-compatible cloud object storage platform that enables service providers and enterprises to build reliable, affordable and scalable hybrid cloud storage solutions. Cloudian actively partners with leading cloud computing environments including Amazon Web Services, Citrix Cloud Platform, Apache CloudStack, OpenStack and the vast ecosystem of S3 compatible tools and applications. Cloudian's customers include Vodafone, Nextel, NTT, Nifty, and LunaCloud. The company has additional offices in China and Japan.
SYS-CON Events announced today that TechXtend (formerly Programmer’s Paradise), a leading value-added provider of server and storage virtualization, and r-evolution will exhibit at SYS-CON's 15th International Cloud Expo®, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. TechXtend (formerly Programmer’s Paradise) is a leading value-added provider of software, systems and solutions for corporations, government organizations, and academic institutions across the United States and Canada. TechXtend is the Exclusive Reseller in the United States for r-evolution