Object-Oriented Analysis and Design with UML and RUP


Part 1: OOP, vocabulary, and UML

Table of Contents
Part 1: OOP, vocabulary, and UML
Part 2: Processes and Unified Process
Part 3: Summary, going further, and remarks

First we will see some general ideas about Object-Oriented Programming (OOP) (without fixing ourself on a particular programming language). We will start first by talking about what is the Object-Oriented Programming, and then some development processes to make OOP easy (such as the Unified Process). It is supposed that you know already how to program, if possible in a object-oriented language (such as C++/Java/C#).

After having read this article should have the basic concepts and references to extend your field of competences in order to program complex softwares within time constraints.

Foreword

Quasi all the new programming languages are object oriented. One of the most widespread remainder still C++. Using an object-oriented language does not mean that you program object-oriented. It is possible to make traditional programming with classes which are in fact of the functions on objects which are in fact structures (Struct in C++). Our goal here is first to define what is an object, object-oriented programming, and to see a method to apply it.

Why program by object

Object-oriented programming is opposed to the traditional programming. In the traditional programming one create function which operate on data. One of the problems of this approach is that the functions vary more often than the data. What we do traditionally is to see the software as a whole with some operations to perform. Then we partition it in functions and sub-function which will operate on our data. The re-use of functions is difficult, but biggest problems is that it is necessary to the structure of the whole software before being able to modify some part of it.

In object-oriented programming we create methods around a group of data that share the responsibilities. We will further see what is an object and a method more in detail; for the moment regard a method as a function acting on the group of data of the object. One of the OOP principles is to have a loose coupling; it means that each object uses few of other objects. Moreover each object is as a black box of which one can modify the interior without modifying their properties nor their behavior. That implies that anyone can directly implement an object (to program the object's code) without knowing anything about the other objects nor about the whole application.

To summarize in a simple words, object-oriented programming facilitates the development of complex programs, facilitates their maintenance, and improves the reusability of the code. Over that and in order to program by object there are software development processes.

Vocabulary: What is an object, a class...

One thing that can seem like a paradox in object programming, and mainly during the analysis, it that we'll avoid restricting ourself to a particular language or give technical programming specifications.

However in the following, we will see each time an example in C++ to illustrate the definition.

Object

An object is an item/unit/entity (real or abstract) unique and identifiable with a well defined role (each object is focused on a well defined set of responsibilities). They are persistent and change state.

Persistant: At the difference in the transitory data, an object must persist and have a history during its life. An object is created at a certain time, changes in state, and it is only destroyed at a direct request of a user or via an authorized object. It must have it's own identity.

Example: Person John; , here John is an object of class Person.

Class

A class is a set of objects which have a common structure and a common behavior. An object is an instance of a class. A class represents the abstract matrix of an object before it's instanciated.

Now that you heard the abstract version, here the more practical version: To create an object you'll write something like MyVariable = new MyClass();. MyVariable is an object here (it is an instance of MyClass), MyClass is the class of the object.

Example: class Person{}; Person John = new Person(); , here John is an object of the class Person and we created a new instance of Person called John. John is a person. Each "person" shares certain common attributes (like the sex, the age...).

Attribute

An attribute is an observable property of the objects of a class.

Example: We add an attributes Age to Person (private here, therefore inaccessible for the moment outside of the class). class Person { private: int Age; };

Method

A method is an operation which can update the value of the certain attributes of an object.

Example: We will add a public method to access the age (the it's going to be a method which does not change any attribute of our object), and another to modify this age. These two methods are commonly called getters and setters. class Person { private: int Age; public: int GetAge() { return Age; } public: void SetAge(int newAge) { Age = newAge; } };

Operation

An operation is also a frequently seen word. This word means a method which is not a getter/setter but really an operation to be carried out on the object.

Example: Here we add an operation which will make it possible to find the age of the person at a given year. class Person { private: int Age; public: int GetAge() { return Age; } public: void SetAge(int newAge) { Age = newAge; } public: int CalulcateAgeIn(int year) { int currentYear = localtime(time(NULL))->tm_year; int birthYear = currentYear - Age; return (year - birthYear); } };

CRC Card

Before starting with more complex elements and in order to consolidate our bases, we will see a mean of describing an object in a very simple way without using a particular language: CRC Cards. They have been invented to easy the training of the OOP.

A CRC Card is very simple a piece of paperboard of size approximately 4x5inches resembling this:

CRC Card

One indicates the name of the class, as well as its responsibilities and, if there is, collaborators. A responsibility is a behavior for which the class is responsible. A responsibility indicates the obligation for an object to have a certain behavior. Some responsibilities may requires the use of other objects. We will put in the column collaborators those other classes.

Analyse

The purpose of the Object-Oriented Analysis (OOA) is to model the field of the problem, the problem which we wish to solve by developing our object-oriented system.

During the analysis you should forget everything related to the application's implementation (or of any technical detail). You should not fix yourself to any language (except specified by the client). Just describe what the software must do, classes and their attributes in a human language with words of the user or the business domain. The user being here the person who will use the software.

To describe an object one can use UML diagrams (see further) or CRC cards.

Example: The above CRC card.

The limits between the phase of analysis and design remain a little vague especially in an iterative process like RUP.

Design

Object-Oriented Design (OOD) is the activity which consists of finding logical solutions to solve a problem.

Once we captured the problem in OOA, we're going find how to solve it. This time we define ourself a programming language and we describe in details the various classes, their interactions, their methods, their attributes according to standards defined.

Example: "To calculate the age" becomes "int CalculateAgeIn(int year)".

Unified Modelling Language (UML)

The UML is a standard to understand and draw various diagrams for OOP. Each type of diagram models an aspect or a particular point of view of our objects, user needs, constraints of the system... Learning UML takes time and to learn how to use it require the double if not more.

UML is not a method to program object-oriented. It does not describe at all how to use it.

The most well know diagram type is the Class Diagram (also called Structure Diagram):

Class Diagram

The digram above is a Class diagram. In a very simple way now that you saw CRC cards, each rectangle corresponds to a CRC card. The 3 compartments correspond respectively to the name of the class, its attributes, its methods.

Even if the UML makes it possible to put in rather clear visual form a whole heap of elements to describe our system, you should known that it can not be used to model everything we need. For example it doesn't describing the user interface or the user interface flowchart, just naming two of them.

Next part: Processes and Unified Process

Parts: 1, 2, 3, Next



Valid XHTML 1.0 Transitional