Friday, May 6, 2011

Step1: Creating Classes for UML Diagrams with their attributes and operations(return type and parameters)


Creating Classes
            Creating Classes is the very important step in creating UML diagrams. This is because it exponentially reduces the time you would require to model your diagrams. Study your problem statement and analyze it thoroughly. Identify the Classes . . .

There are 4 ways of identifying classes:

 1. Noun Phrase Method

         In this method you have to identify each and every noun in the problem statement and checklist it. Then try to eliminate them on the basis that they cannot become fully fledged classes; they are better as attributes of classes or that they are not required at all.

2. CRC - Class Responsibility Collaboration
         In this method you draw a CRC as shown below. This would help you to determine the functions of the Classes and other Classes that are connected to this Class. 


 The left Column consist of the Class’ member functions and attributes and the right column consists of its relationships with other columns.
3. Use Case Driven
         In this method you are expected to identify classes from use case scenarios. But in this case you will need to identify the scenarios first, which we will learn when we will see how to prepare a Use-Case Diagram.

4.Common Class Pattern Approach  
        This approach asks you to define Classes with fixed and universal functionalities. E.g. an ATM system Class in Banking Application. Various other patterns that may be defined are: Organization Class, People and Person, Devices, Places, etc.

 The best and relatively simpler approach to identifying classes, we would suggest, is the ‘Noun Phrase Approach’.

 Assuming that you have identified your Classes for your Problem Statement we should now see how to create a Class in Rational Rose, how to define its attributes, operations and functions, arguments and parameters, return type and relations with other Classes.
  
 




 We have created a Class in Rational Rose. For understanding purpose we have named it ‘NewClass’. It will appear as a Sub-Menu under the Menu ‘Logical View’. Now it’s time we define its properties. Double Click on the Sub-Menu ‘NewClass’ or Right Click on the Class name and select ‘Open Standard Specification’.


The Specification Window would then appear. This Specification Window has various tabs. Go to the ‘Attribute’ tab, then Right Click on the White space and select ‘Insert’. We have here added 3 attributes.


Double Click on each attribute to open its respective Specification Window. Take a look in the previous picture that we have set the type of attribute attb1 as String. You could use others such as Integer, Float, etc.


Now that we are done with attributes, we would now move on to Operations.

Click on the Operations tab on the Class specification Window. And Right Click on the White Space and click Insert. We have created three operations: operation1, operation2, operation3. Double clicking each operation would open its specification Window where you would set its return type and arguments.


To set the return type of Operation1, open its specification window. Select the return type as shown below.


To set the arguments click on the Detail tab. You can insert as many parameters you would like. But you have to remember that whatever arguments you use should be attributes of that class with same name and data type. This is because when we will generate code from our diagrams the arguments and parameters that will be passed to our operations will be stored in the attributes and variables of the class. E.g. we have used attb1 as parameter of operation1 and attb1 have same name and type (String).


This procedure should be followed for every Class that you intend to use in your Class Diagram, Sequence Diagram, Use-Case Diagram, Activity Diagram, Component Diagram, Deployment Diagram, etc.
Once your class is ready you would see something like this in your RR Browser.



We know that this takes time. But this will definitely reduce the time that you would have otherwise required to draw your diagrams.

In further posts we would see how to use these classes in our diagrams.

Your comments would encourage us to continue our work. For personal queries you can mail to bitstogather@gmail.com