Suite101

OOP Programs and Methods

Introduction To UML

© Ken Standard

The use of C++ as a programming language is made much easier when using conceptual models. UML provides a common and consistent platform to do just that.

Many programmers migrate from other procedural languages like C or Pascal to C++. In that process there is a tendency to retain much of the “everything is a function” mentality. In C++, functions are an integral part of the language. However, C++ uses a different program design philosophy than Pascal or even the venerable C language. This gives rise to a mistaken habit of creating a class for each new operational need. Many applications are bloated with too many classes as a result of not understanding the guiding philosophy of C++ since it's introduction in 1985.

To understand that philosophy, one must “rethink” how programs are designed (that is to say the underlying conceptual architecture). When designing programs in C++ one must think in terms of “objects”. Object Oriented Programming (fondly referred to as OOP) is essentially building a program around self-contained collections of data and code (the object) to modify that data; this programming model is in contrast to a model that uses functions that act externally on data scattered throughout a program. Object-oriented coding is an organizational and conceptual style. It also helps programmers create reusable code because the code to do a specific thing is entirely contained within a single section of code or module, and to use the code to perform tasks - for instance, creating a menu - involves using only a small number of functions to access the internals of the code. Different menus may be created the same way using different data. Think of it as a black box. You do not need to know how the box operates or why it works – only that what it does and how to make it perform the stated purpose. Object-Oriented Programming simplifies the use of code by another program or module by encapsulating it (the black box image). The menu code can be reused whenever a menu needs to be created or modified. It could be called a “menu object” for your application.

Functions on the other hand are not so portable or flexible. Functions are made for a particular purpose, with specific operating parameters. It is true that objects (i.e. Classes) have functions to do work. However the general role of the function in a class is to serve an INTERNAL purpose (internal to the class). Objects represent a collection of functions that serve a collective purpose and perform a particular EXTERNAL purpose. We don't care what functions are in the class, only that we are able to perform a particular purpose. We don't care how the functions do their magic, just that we can accomplish the purpose the object was designed to do. This design philosophy, is more easily grasped by programmers new to C++ than those transitioning from similar languages.

As an outgrowth of emerging software technology like C++, design tools also emerged to aid in design of conceptual models. Such a design tool is the Unified Modeling Language (often just referred to as UML). UML seeks to model using use and purpose rather than sweat the details of designing a function. UML models have scenarios with high sounding names like Use Case Model, and Class Model. In these scenarios the conceptual relationship of one class to another and to the user (called an actor in UML) and the usage of each are diagrammed and defined.

Even though C++ programs can be constructed by hand, the use of UML provides a straightforward and consistent interface for the user to generate C++ code in the same way every time. Some UML tools even allow you to import C++ code and create a UML model. This is known as Reverse Engineering. When a UML modeling program allows the Forward and Reverse engineering of C++ (or Java for that matter) it is called “round trip” modeling.

Microsoft Visual Studio has provided a degree of “round trip” modeling for some time. Other third party vendors like Rational Software have integrated their products with popular programming platforms like Visual Studio. GNU products are now available that can generate GNU compatible C++ and Java code on demand. There is also some for sale products that will also generate GNU acceptable code, plus provide a number of useful features to the object modeler – all without the modeler manually creating a line of code. UML models serve as the foundation of a considerable number of Internet based applications in service today.


The copyright of the article OOP Programs and Methods in Computer Programming is owned by Ken Standard. Permission to republish OOP Programs and Methods in print or online must be granted by the author in writing.





Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo