
Database Modelling in UML By Geoffrey Sparks, [email protected] : http://www.sparxsystems.com.au Originally published in Methods & Tools e-newsletter : http://www.martinig.ch/mt/index.html Introduction Data Profile (as proposed by Rational Software). When it comes to providing reliable, Some familiarity with object-oriented flexible and efficient object persistence design, UML and relational database for software systems, today's designers modelling is assumed. and architects are faced with many choices. From the technological The Class Model perspective, the choice is usually between pure Object-Oriented, Object- The Class Model in the UML is the Relational hybrids, pure Relational and main artefact produced to represent the custom solutions based on open or logical structure of a software system. proprietary file formats (eg. XML, It captures the both the data OLE structured storage). From the requirements and the behaviour of vendor aspect Oracle, IBM, Microsoft, objects within the model domain. The POET and others offer similar but techniques for discovering and often-incompatible solutions. elaborating that model are outside the scope of this article, so we will assume This article is about only one of those the existence of a well designed class choices, that is the layering of an model that requires mapping onto a object-oriented class model on top of a relational database. purely relational database. This is not to imply this is the only, best or The class is the basic logical entity in simplest solution, but pragmatically it the UML. It defines both the data and is one of the most common, and one the behaviour of a structural unit. A that has the potential for the most class is a template or model from misuse. which instances or objects are created at run time. When we develop a logical We will begin with a quick tour of the model such as a structural hierarchy in two design domains we are trying to UML we explicitly deal with classes. bridge: firstly the object-oriented class model as represented in the UML, and When we work with dynamic secondly the relational database model. diagrams, such as sequence diagrams and collaborations, we work with For each domain we look only at the objects or instances of classes and their main features that will affect our task. inter-actions at run-time. We will then look at the techniques and issues involved in mapping from The principal of data hiding or the class model to the database model, encapsulation is based on localisation including object persistence, object of effect. A class has internal data behaviour, relationships between elements that it is responsible for. objects and object identity. We will Access to these data elements should conclude with a review of the UML be through the class's exposed behaviour or interface. Adherence to Person Person Class attributes : the encapsulated - Address: CAddress data # Name: # Age:St i double + getAge() : int + setAge(n) + getName() : +setName(s)St i A simple person class with no state or Class operations: behaviour shown the behaviour Attributes and operations define the state of an object run-timet and the capabilities or behaviour of the bj t Figure 1 - Classes, attributes and operations this principal results in more relationship that is most interesting: for maintainable code. example an Address class may be associated with a Person class. The Behaviour mapping of this relationship into the relational data space requires some Behaviour is captured in the class care. model using the operations that are defined for the class. Operations may Aggregation is a form of association be externally visible (public), visible to that implies the collection of one class children (protected) or hidden of objects within another. Composition (private). By combining hidden data is a stronger form of aggregation that with a publicly accessible interface and implies one object is actually hidden or protected data manipulation, composed of others. Like the a class designer can create highly association relationship, this implies a maintainable structural units that complex class attribute that requires support rather than hinder change. careful consideration in the process of mapping to the relational domain. Relationships and Identity While a class represents the template Association is a relationship between 2 or model from which many object classes indicating that at least one side instances may be created, an object at of the relationship knows about and run time requires some means of somehow uses or manipulates the other identifying itself such that associated side. This relationship may by objects may act upon the correct object functional (do something for me) or instance. In a programming language structural (be something for me). For like C++, object pointers may be this article it is the structural passed around and held to allow objects access to a unique object with which to locate or re-create the instance. required object. Often though, an object will be destroyed and require that it be re- The Relational Model created as it was during its last active instance. These objects require a The relational data model has been storage mechanism to save their around for many years and has a internal state and associations into and proven track record of providing to retrieve that state as required. performance and flexibility. It is essentially set based and has as its Inheritance provides the class model fundamental unit the 'table', which is with a means of factoring out common composed of a set of one or more behaviour into generalised classes that 'columns', each of which contains a then act as the ancestors of many data element. variations on a common theme. Inheritance is a means of managing Tables and Columns both re-use and complexity. As we will see, the relational model has no direct A relational table is collection of one counterpart of inheritance, which or more columns each of which has a creates a dilemma for the data unique name within the table construct. modeller mapping an object model Each column is defined to be of a onto a relational framework. certain basic data type, such as a number, text or binary data. A table Navigation from one object at run time definition is a template from which to another is based on absolute table rows are created, each row being references. One object has some form an instance of a possible table instance. of link (a pointer or unique object ID) A class hierarchy Person Aggregation captures the concept Family showing a generalised collectionof or composition between classes person class from which other classes are derived Parent Child The main relationships we are interested in are Association, 2 Aggregation and Inheritance. 1..n These Association captures describe the ways classes interact a having or using or relate to each other relationship between classes Figure 2 - UML Class model notation Share A Person may own a set of Shares A Person is composed of a strict set of ID 0..n A Person may documents (having n reside at zero elements) or more addresses 0..1 Address Person ID Document 0..n 0..n 1 n An Address may Three forms of the Aggregation relationship. The weak form is have zero or depicted with an unfilled diamond head, the strong form more Persons in (composition) with a filled head. residence Figure 3- Aggregation Relationships Public Data Access Database stored procedures provide a means of extending database The relational model only offers a functionality through proprietary public data access model. All data is language extensions used to construct equally exposed and open to any functional units (scripts). These process to update, query or manipulate functional procedures do not map it. Information hiding is unknown. directly to entities, nor have a logical relationship to them. Behaviour Navigation through relational data sets The behaviour associated with a table is based on row traversal and table is usually based on the business or joins. SQL is the primary language logical rules applied to that entity. used to select rows and locate instances from a table set. Constraints may be applied to columns in the form of uniqueness Relationships and Identity requirements, relational integrity constraints to other tables/rows, The primary key of a table provides the allowable values and data types. unique identifying value for a particular row. There are two kinds of Triggers provide some additional primary key that we are interested in: behaviour that can be associated with firstly the meaningful key, made up of an entity. Typically this is used to data columns which have a meaning enforce data integrity before or after within the business domain, and updates, inserts and deletes. second the abstract unique identifier, such as a counter value, which have no business meaning but uniquely identify Having looked at the two domains of a row. We will discuss this and the interest and compared some of the implications of meaningful keys later. important features of each, we will digress briefly to look at the notation A table may contain columns that map proposed to represent relational data to the primary key of another table. models in the UML. This relationship between tables defines a foreign key and implies a The UML Data Model Profile structural relationship or association between the two tables. The Data Model Profile is a proposed UML extension (and currently under Summary review - Jan 2001) to support the modelling of relational databases in From the above overview we can see UML. It includes custom extensions that the object model is based on for such things as tables, data base discrete entities having both state schema, table keys, triggers and (attributes/data) and behaviour, with constraints.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages16 Page
-
File Size-