Previous Next
Designers Guide Chapter 3 - Designing Object Model with UML Class Diagram

Chapter 3 - Designing Object Model with UML Class Diagram

DB Visual ARCHITECT (DB-VA) provides you a visual modeling environment for the object model of an application. This chapter shows you how to depict the object models by using a UML Class Diagram.

In this chapter:

Introduction

An object is a self-contained entity with well-defined characteristics and behaviors while the characteristics and behaviors are represented by attributes and operations respectively. A class is a generic definition for a set of similar objects. Hence, an object is an instance of a class. An object model provides a static conceptual view of an application. It shows the key components (objects) and their relationships (associations) within the application system.

DB-VA supports visual modeling for object models, not only by creating a new object model, but also by transforming from a data model. As DB-VA automates object-relational mapping, DB-VA supports the generation of database, code and persistence layer for Java model API and .NET model API, which in turn streamlines the model-code-deploy software development process.

Creating Object Model with Class Diagram

A class diagram can be used to describe the objects and classes inside a system and the relationships between them; and thus, a class diagram is also known as an object model. The class diagram identifies the high-level entities of the system. DB-VA comes with a complete UML 2.0 class diagram for object modeling.

The following section describes how you can depict an object model using the class diagram. DB-VA also supports the generation of persistent code based on the object model, which will be briefly described in the DB-VA Programmer's Guide.

DB-VA provides you with two ways to create a Class Diagram:

  1. Drawing a Class Diagram
  2. Synchronizing from Data Model to Object Model

Drawing a Class Diagram

You can create a new class diagram in one of the three ways:

A new class diagram pane is displayed.

Adding Class

  1. On the diagram toolbar, click the Class shape icon.
  2. Figure 3.3 - Class shape icon
  3. Click a location in the diagram pane.
  4. DB-VA places an icon representing the class element on the diagram.
  5. Type a name for the Class element.
Adding ORM-Persistable Class

ORM-Persistable class is capable of manipulating the persistent data with the relational database. In supporting the generation of persistent code, ORM-Persistable classes should be used in object modeling. Classes added to the class diagram can be stereotyped as ORM-Persistable to manipulate the database. For information on how to specify the stereotype to a class, refer to Specifying Stereotypes section.

DB-VA provides an alternative way to add the ORM-Persistable class easily.

  1. On the diagram toolbar, click the Class shape icon and hold for a while, a pop-up menu shows.
  2. Figure 3.4 - Click on Class shape icon
  3. Select ORM-Persistable Class from the pop-up menu.
  4. Figure 3.5 - Select ORM-Persistable Class on popup menu
  5. Click a location in the diagram pane.
  6. DB-VA places a class shape icon which is marked with <<ORM Persistable>> on the diagram.

    Figure 3.6 - ORM Persistable Class
  7. Type a name for the ORM-Persistable Class.
Modifying Class Specification

A class specification displays the class properties and relationships.

You can display the Class Specification in one of the two ways:

Class Specification dialog box is displayed, you can modify the class properties and relationships.

 

Figure 3.9 - Class Specification dialog

Adding Attribute

An attribute is a property of a class which has a name, a value and also has a type to describe the characteristic of an object.

  1. You can add attribute to the class in one of the three ways:
A new attribute is added, type the attribute name and type in the form of "attribute_name: type". You can also edit the attribute name by double-clicking the attribute name or by pressing the F2 button.

 

Modifying Attribute Specification

An attribute specification displays the attribute properties, such as name, type, and initial value etc.

To open the Attribute Specification:

  1. Right-click the attribute, click Open Specification...from the pop-up menu.
  2. Figure 3.12 - To open attribute specification

    The Attribute Specification dialog box is displayed, you can modify the attribute properties.

    Figure 3.13 - Attribute Specification dialog

Adding Association

An association refers to the relationship specifying the type of link that exists between objects. It shows how the objects are related to each other.

You can add an association to the classes in one of the two ways:

A connector is added between the two classes.

Figure 3.18 - An association are created
DB-VA automatically creates the roles in an association between ORM-Persistable classes.
Modifying Association Specification

You can edit the association specification in one of the three ways:

Adding Operation

An operation, also called function or method is the behavior of an object relates to how it acts and reacts.

You can add operation to the class in one of the three ways:

A new operation is added, enter the operation in the form of "operation_name(parameter_name: type) : return_type". You can also edit the operation name by double-clicking the operation or by pressing the F2 button.

 

Modifying Operation Specification

An operation specification displays the operation properties, such as name, visibility, return type, and parameters etc.

To open the Operation Specification:

  1. Right-click the operation, click Open Specification... from the pop-up menu.
  2. Figure 3.24 - To open operation specification

    The Operation Specification dialog box is displayed, you can modify the operation properties.

    Figure 3.25 - Operation Specification dialog

Adding ORM Implementation Class

ORM-Persistable class is used to generate the persistent class which has the ability to access the database including the basic operations for add, update, delete and search. As the generated code provides the basic operations for manipulating the persistent data, you may find it insufficient and want to add extra logic to it.

DB-VA promotes the use of ORM Implementation Class to add extra logic to the ORM-Persistable class. When generating the persistent code, the ORM implementation class will also be generated, and thus you can implement the logic to the method in the generated implementation class for manipulating the persistent data.

To add an ORM implementation class:

  1. Create an ORM-Persistable class with an operation for adding extra logic.
  2. Figure 3.26 - ORM-Persistable class with an operation
  3. Mouse over the class and drag the resource of "Create ORM Implementation Class" to the diagram pane.
  4. Figure 3.27 - "Create ORM Implementation Class" resource

The implementation class is created and connected to the source class with generalization stereotyped as <<ORM Implementation>>. The source class becomes an abstract class with an abstract operation.

Figure 3.28 - ORM Persistable Class and ORM Implementation Class

Synchronizing from Data Model to Object Model

DB-VA allows you to generate a Class Diagram from an ERD by synchronization if there is an ERD.

You can synchronize the ERD to Class Diagram in one of the three ways:

Defining Package for Classes

DB-VA provides you with two alternative ways to define the packages for the classes.

After defining the packages to the classes, the classes are inside the package and depicted on the class repository.

Figure 3.36 - Class Repository show the Classes in the package

Specifying Stereotypes

Stereotype extends the semantics of the UML metamodel. It classifies the element in what respects it behaves as an instance of metamodel. In order to enable the mapping between object model and relational database, the class has to be stereotyped as ORM Persistable.

To specify the stereotypes of a class:

  1. Right-click a class, select Stereotypes > Stereotypes....
  2. Figure 3.37 - To add/remove stereotypes

    The Class Specification dialog box is shown with Stereotypes Tab

    Figure 3.38 - Class Specification dialog (Stereotypes Tab)
  3. Select ORM Persistable, then > button and OK.
  4. Figure 3.39 - Class with stereotypes

Specifying Inheritance Strategy

In a generalization, the subclass inherits all the features of the superclass. DB-VA provides two inheritance strategies - table per class hierarchy and table per subclass to transform the generalization hierarchy to relational model. By default, table per class hierarchy is used for the generalization.

When transforming generalization into relational model, DB-VA transforms the generalization according to the inheritance strategy applied. For more information on the transformation, refer to the description of Mapping Inheritance/Generalization section.

You can specify the inheritance strategy in one of the two ways:

These two inheritance strategies can be applied to different subclasses within a generalization hierarchy in Java project. Applying two strategies to different subclasses within a generalization in .NET project will result in error when the generation of code and database.

Specifying Collection Type

If one end of an association contains a multiplicity of many, a collection class will be generated for handling the multiple instances. DB-VA allows you to specify the type of collection, including set, bag, list and map.

Set is an unordered collection that does not allow duplication of objects. Bag is an unordered collection that may contain duplicate objects. List is an ordered collection that allows duplication of objects. Map is an ordered collection that maps keys to values while each key can map to exactly one value.

You can specify the collection type in one of the two ways:

Defining ORM Qualifier

ORM Qualifier is used to specify the extra retrieval rules of the generated persistent class for querying the database. DB-VA allows you to define the ORM Qualifiers of the classes in the class diagram before the generation of persistent code. For more information on the usage of ORM Qualifier, refer to the DB-VA Programmer's Guide.

  1. Open the ORM Qualifier tab inside the Class Specification dialog box in one of the two ways:
  2. Click Add, the ORM Qualifier Specification dialog box is displayed with a list of attributes of the selected class.
  3. Enter the name of the ORM Qualifier, place a check mark for the Key column of the attribute that will be used in querying the database.
  4. Figure 3.51 - ORM Qualifier Specification dialog
  5. Click OK to confirm adding the ORM Qualifier. The newly added ORM Qualifier is listed on the ORM Query tab.
  6. Figure 3.52 - ORM Qualifier added in the ORM Qualifiers list

Customizing SQL

DB-VA generates SQL statements which are ready-to-use for accessing the database. In some cases, you may find the generated SQL statements not appropriate for your needs. DB-VA allows you to override the generated SQL statements, including the Insert, Update and Delete statements whenever you want to.

To customize the generated SQL statements:

  1. Right-click on an ORM-Persistable class that you want to customize the SQL statements, select ORM > ORM Class Details...from the pop-up menu. The Class Specification dialog box showing the ORM Class Detail tab is displayed.
  2. Figure 3.53 - Open the ORM Class Detail
  3. Select the type of SQL statement that you want to customize.
  4. Figure 3.54 - Class Specification dialog (ORM Class Detail)
  5. Click Generate SQL to generate the ready-to-use SQL statement.
  6. Figure 3.55 - Generate Insert SQL statement

    The SQL statement is generated based on the property of class.

    Figure 3.56 - The generated Insert SQL statement
  7. Modify the SQL statement to the desired one.
  8. Figure 3.57 - The modified SQL statement

     

 


Previous Next
Visual Paradigm International Limited
Website: www.visual-paradigm.com
E-mail: support@visual-paradigm.com