T-1.Intro to OO Modeling

Document Sample
T-1.Intro to OO Modeling Powered By Docstoc
					TUTORIAL
Part 1 - OO Modeling with WithClass
1. Introduction to OO Modeling, Scripting, and C++
by Richard C. Felsinger fro Microgold Software, Inc.
WithClass Scripting WithClass Tool developed by Michael Gold

The purpose of this tutorial is to present "step by step" instructions on how to model, program, and script
an object-oriented system. This tutorial uses a scripting CASE tool to create object-oriented diagrams,
fill-in specification forms, generate C++ with code generation scripts, and to create code generation
scripts. A script is a program (set of script statements) that prints out text statements for reports and
code. This tutorial presents the Object Modeling Technique (OMT) presented in Object-Oriented Modeling
and Design by James Rumbaugh, Michael Blaha, William Premerlani, Frederick Eddy, and William
Lorensen. All specifications are based upon Object-Oriented Design with Applications by Grady Booch.
This tutorial primarily uses WithClass. This tutorial presents a few specification items and script variables
in addition to those provided in the WithClass tool fill-in specification forms.


To create the various diagrams, text specifications, and C++ code in this tutorial, you should have access
the following Windows programs:
         A Windows scripting CASE tool such as the WithClass tool from Microgold Software to create class
          diagrams, text specifications, and C++ code files,
         Any Windows drawing tool to create drawings, block diagrams, and other diagrams,
         Any C++ compiler environment to compile, link, and run C++ code files.


OO modeling means to create object-oriented diagrams, text specifications, and code to describe a
system, subsystems, and classes. It is to examine a problem from different points of view and to create
a software solution to the problem. Just as an automotive design engineer creates drawings, clay models,
and text specifications of a new car, we create diagrams, text specifications, and code to describe a new
software system. The ultimate aim is to create a new software system (computer program) for the
problem that has excellent S/W quality factors, e.g. correct, reliable, and modifiable.


Inputs Process of OO Modeling Outputs
         System Object Model Diagrams
         Requirements Dynamic Model Text Specifications
         Functional Model Code & Prototypes




OO Modeling with WithClass - Microgold Software Inc. www.microgold.com
TUTORIAL OBJECTIVES


There are two primary objectives of this tutorial. The first objective is to present how to model and
prototype in C++ a simple class using WithClass. One example will be provided: a car that a user can
start, operate, stop, add a passenger, remove a passenger, make a cellular phone call, and receive a
cellular phone call.


The second objective is to present how to model and prototype a simple system in C++. One example
will be provided: a TV controller to manipulate the volume and channel settings. All examples will use
a variety of documentation products, e.g. diagrams, text specifications, and code.


Figure 1.1. OO Modeling is the process of creating the object, dynamic, and functional models.




In OO modeling we will follow a progression as shown below:

1st - State the objective or problem, e.g. a transportation system.


2nd - Create OO diagrams, e.g. class diagrams.


3rd - Create OO text specifications, e.g. class specification.


4th - Find or update the appropriate report and code generation scripts


5th - Generate code with the WithClass tool.


6th - Update and execute the code for an executable prototype, e.g. C++.


7th - Reverse engineer the code to update diagrams and specifications.



The basic inputs and outputs in OO modeling are shown below. We'll start with a problem such as
"model a car'. We'll use an OO methodology to describe the car from an object (classes and
relationships), dynamic (messages and states), and functional (data computation) points of view.
We'll work to achieve S/W quality factors such as correctness and reliability. We'll use various Windows
tools such as WithClass and C++ development environments. We'll produce various OO diagrams,
text specifications, CASE tool generated C++ code, and finally updated C++ code for an executable
prototype.


         Objective OO S/W Quality Factors Report Windows Tools



OO Modeling with WithClass - Microgold Software Inc. www.microgold.com
                                                                                                           2
         Problem Methodology - Techniques and Code WithClass, GUI,
         Object, Dynamic, Generation C++ Environment
         Functional Models Scripts Libraries
         OO Diagrams - OO Specifications - Generated Updated Code
         Class, State Class, Attribute, Code for Executable Operation Prototypes


WHY IS OO MODELING IMPORTANT?


OO modeling provides an effective framework to analyze, design, and prototype systems. It is well suited
for today's OO languages such as C++, Objective-C, Eiffel, Ada 9X, Object Pascal, Delphi, Object COBOL,
etc. It is well suited for emerging OO data base management systems. The traditional functional
decomposition software methodology was useful for procedural languages such as C, FORTRAN,
and COBOL. However, OO modeling provides substantial advantages over the functional decomposition
methodology. OO modeling provides the following:

         A framework of OO entities (system, class, object) and relationships (association, aggregation,
          generalization specialization) to develop OO systems with a seamless transition from analysis
          models to working prototypes.

         A set of integrated CASE Tools and software development tools and environments to rapidly
          model and prototype systems.

         Different points of view to analyze and design a system with the object model, dynamic model,
          and functional model.

         An aid to create high quality software that is correct, reliable, extendible, and reusable.
         A direct correspondence between the physical real world and the computer software for
          understandable, modifiable systems.

         A means to rapidly develop models and prototypes with tools and libraries.


OO modeling has many benefits. The following are several quotations on the benefits of OO modeling.
Boehm-Davis and Ross stated "The completeness, complexity, and design time data would seem to
suggest that there is an advantage to generating program solutions using...object-oriented methods.
The object-oriented method seemed to produce better solutions for [a problem] which involved real-time
processing" [Boehm-Davis-84]. Borgida stated "The chief advantage of object-oriented frameworks is
that they make possible a direct and natural correspondence between the world and its model"
[Borgida-85]. Booch stated "In general, understandability and maintainability are enhanced due to the
fact that objects and their related operations are localized" [Booch-86]. Bernard stated "Concepts such
as module coupling and module cohesion are addressed virtually automatically by OOD. Specifically, OOD
done correctly, will almost always result in modules which are highly cohesive (i.e. perform a single
specific function) and loosely coupled (i.e. the interconnection between modules will be fairly weak)"
[Berard-86]. Winblad, Edwards, and King stated "Ask don't touch...Design applications by snapping
together the necessary objects" [Winblad-90].


DOCUMENTATION PRODUCTS FOR OO MODELING


There are three major documentation products for OO modeling: diagrams, text specifications, and code
as described below:




OO Modeling with WithClass - Microgold Software Inc. www.microgold.com
                                                                                                            3
Figure 1.2. Major Documentation Products in OO Modeling


Diagrams


The major OO diagrams to be created using WithClass are the system diagram, class diagram, event flow
diagram, and object interaction diagram. A major diagram to be created with WithClasss is the state
diagram. System drawings and interface drawings will be created using WithClass or a Windows drawing
tool. These diagrams may also be created using any WithClass tool or full-featured drawing tool. Drawing
tools like Shapeware's Visio may be used to create diagrams.


Text Specifications


There are many text forms used in OO modeling. These include system requirements statements, data
dictionaries, class specifications, event lists, and interaction scenarios (messages). The WithClass tool or
a Windows word processor will be used to create text specifications.


Code


Source code in C++ will be initially generated using WithClass. Then this generated code will be compiled
using Borland C++ or Visual C++. Next messages and transformations will be added to the source code
for a full executable C++ prototype.


WINDOWS TOOLS FOR OO MODELING


There are four major windows tools for OO modeling: windows word processor for text specifications and
simple diagrams; WithClass tool for OO diagrams, text specifications, and C++ code generation; GUI
interface builder for GUI prototypes and code generation; and C++ development environment. In this
tutorial the following windows tools are used:

         Windows word processor - Microsoft Word and Lotus AmiPro


OO Modeling with WithClass - Microgold Software Inc. www.microgold.com
                                                                                                           4
         WithClass tool - MicroGold
         GUI interface builder - Microsoft Visual C++ App Studio or Borland C++ Resource Workshop
         C++ development environment - Microsoft Visual C++ or Borland C++.


Windows Word Processor


The windows word processor is important to create text specifications and simple drawings. A windows
word processor has both text creation and simple drawing creation tools. It has the capability to tie
together and integrate text and graphics from several windows tools using the clipboard, dynamic data
exchange, or object linking and embedding. The following are several word processors that are useful for
OO Modeling in the Microsoft Windows environment: Microsoft Word, Lotus AmiPro, Word Perfect, and
Frame Technology FrameMaker.


WithClass Tool


WithClass can be used to create OO diagrams, text specifications, and C++ code generation. WithClass
provides the capability to create custom scripts for code generation and report creation. With scripts an
end-user can write short scripts that access and manipulate the information in a model exactly as he or
she desires. Scripts provide great flexibility and extendibility. WithClass is very helpful for OO modeling
because it provides a structure to create diagrams, text specifications, and code. Additionally, WithClass
saves time because diagrams, text specifications, and code may be quickly created and changed. Finally,
WithClass is valuable for training and education to understand the various OO entities, OO relationships,
and OO methodologies.


The primary CASE tool used in this tutorial is WithClass.This tool provides support for all major diagrams
and specifications in the Rumbaugh OMT. It provides a script language to create reports and to generate
source code in C++ and other languages.


GUI Interface Builder


A GUI interface builder is important to design and prototype the GUI interface. The GUI interface is an
important aspect of an OO system because it provides direct contact with the user. Often prototyping the
GUI interface is extremely valuable to understand the user requirements. GUI interface builders will be
used in modeling systems later in this tutorial. The following are several GUI Interface Builders that are
useful in the Microsoft Window environment: ProtoView Development Protogen +, Blue Sky
WindowsMaker, Borland C++ Resource Workshop, and Microsoft Visual C++ App Studio.


C++ Development Environment


The C++ development environment is important to develop working system prototypes and to develop
implementation products. The environment has many tools, e.g. class browser, compiler, linker,
debugger, GUI builder, and class libraries. Important C++ development environments in the Microsoft
Windows environment are the Borland C++, Microsoft Visual C++, and Symantec C++.




OO Modeling with WithClass - Microgold Software Inc. www.microgold.com
                                                                                                              5
OBJECTIVES OF OO MODELING - S/W QUALITY FACTORS


The primary objective of OO modeling is to describe and specify a system to lead to a high quality
software program. A quality software program has the major S/W quality factors of correctness,
relia-bility, and extendibility as described by Bertrand Meyer in Object-Oriented Software Construction
[Meyer-88]. Other S/W quality factors include understandability, adaptability, reusability, efficiency,
portability, traceability, completeness, confirmability, modularity, error handling, uniformity, and ease
of use.


Correctness


Correctness is the ability of a system to perform in accordance with its stated purpose and requirements.
Correctness is "doing what it is supposed to do". It ensures that correct values are always computed.
It ensures that there is correct stimulus response behavior of a system or object. Correctness is to avoid
errors. For example, it is important for a bank automatic teller machine to correctly verify a user card,
personal identification number, and to correctly update account balances.




Figure 1.3. Correct Calculation by an ATM


Reliability


Reliability is the ability of a system to perform correctly for long periods of time. Reliability is sometimes
referred to as "robustness", i.e. the ability of a system or object to perform correctly even under
abnormal conditions. It ensures that a system or object has the capability to detect errors and faults and
to take appropriate action. For example, it is important for a bank automatic teller machine to operate
for long periods of time without problems and errors.




Figure 1.4. Reliable Operation of an ATM




OO Modeling with WithClass - Microgold Software Inc. www.microgold.com
                                                                                                                 6
Extendibility


Extendibility is the ability to easily change and update a system. It deals with making both minor
changes to the existing entity and making major enhancements to the entity. Changes and
enhancements should not cause a "ripple effect" of undesired problems in other entities. It means that
a system can be easily modified and extended. For example, it is important for a bank to easily make
changes and modifications to a bank automatic teller machine without causing undesired side effects and
problems.




Figure 1.5. Extendibility in an ATM


Reusability


Reusability is the ability to use or reuse an application or a part of an application for new applications.
It involves using predefined classes and objects when they are available to reduce the amount of new
code in an application. It also involves modifying an application for a new use. For example, the bank
ATM shown below was modified to handle rental car reservations as shown below.




Figure 1.6. Reusability in an ATM


In summary, to create a high quality software system, we model the system from various points of view
with various documentation products. This is to lead to a software system with excellent S/W quality
factors of correctness, reliability, and extendibility.


TECHNIQUES TO ACHIEVE QUALITY SOFTWARE


How do we achieve the software quality factors of correctness, reliability, extendibility, and reusability?
We can apply certain techniques or guidelines such as encapsulation, loose coupling, strong cohesion,
aggregation with propagation of operations, and subclasses with polymorphic operations. These
techniques are shown below.



OO Modeling with WithClass - Microgold Software Inc. www.microgold.com
                                                                                                              7
Effective Techniques Software Quality Factors
         Encapsulation Correctness High
         Weak Coupling Reliability Quality
         Strong Cohesion ==> Extendibility ==> S/W

         Aggregation & Propagation Reusability
         Subclasses & Polymorphism


Encapsulation


Encapsulation means to combine (encapsulate) data and the operations on the data. Encapsulation is
also known as information hiding in which data and some operations are hidden and inaccessible. An
important aspect of encapsulation is to separate the "what" and the "how". The "what" is the public
interface of available operations. The "how" is the private implementation of data and some operations.
In the physical world a vending machine is a good example of encapsulation. The vending machine
encapsulates the products, such as soft drinks and the operations on the products, such as
select_product and dispense_product. There is information hiding because a user cannot directly
manipulate the products. A user can only use the buttons and levers on the vending machine. The
vending machine case hides the internal storage of the products. The vending machine separates the
"what", represented by the visible (public) buttons and levers, from the private implementation, which
is the storage and dispensing mechanism.




Figure 1.7. Encapsulation in a Vending Machine


A good example of encapsulation in software is a collection class. The collection class encapsulates the
items in the collection, such as numbers, strings, etc., and the operations on the items in the collection,
such as add_item and remove_item. There is information hiding because a user cannot directly
manipulate an item in the collection. A user can only invoke the operations. The collection hides the
internal storage of the items. The collection separates the "what", the public operations add_item and
remove_item, from the private implementation, the storage of the items. A class or other module that
has a public interface and private implementation is also referred to as an abstract data type
[Cleaveland-86].




OO Modeling with WithClass - Microgold Software Inc. www.microgold.com
                                                                                                              8
Weak Coupling


Weak coupling is another technique to achieve the software quality factors. Weak coupling is to have
a low degree of interconnectivity of entities. The general term coupling refers to the degree of
interconnectivity, joining, and linking of entities. With weak coupling a change in one entity will generally
have a minimum change in another entity. It is also referred to as loose coupling. Strong coupling is to
have a high degree of interconnectivity of entities. With strong coupling a change in one entity may
result in a change to the other entity.


In the physical world, an example of weak coupling is a boy and girl walking down a street talking. There
is a low degree of interconnectivity between the boy and the girl. A change in the boy or the girl will have
a minimum change in the other. If the boy accidentally stumbles, he will probably not cause the girl to
stumble. Another example of loose coupling is a modular stereo set as shown in the figure below.
The components are connected together (coupled) with easy to change cables. There is a low degree of
interconnectivity because a component may be easily changed without affecting other components.
In software an example of weak coupling would be the several objects in an automatic teller machine
that have a moderate (not excessive) small number of association relationships. Therefore a change in
one of the objects, such as a card object will not cause an undesired change in the another object, such
as an account object.




Figure 1.8. Weak coupling in a Modular Stereo System


In the physical world, an example of strong coupling would be two steel beams that are welded together.
There is a high degree of interconnectivity between the beams. To move one of the beams you must
move the other. Another example is a single unit stereo system with soldered hard wired cables. There is
a high degree of interconnectivity between the components. A component cannot be easily changed
without affecting other components. In software an example of strong coupling is a group of objects with
a large number of relationships resulting in an intertwined organization. A change in one object may
result in an undesired side-effect in another object.


Strong Cohesion


Strong cohesion is a technique to achieve software quality factors. Cohesion is the degree of internal
relatedness of elements within a larger, more complex entity. Each element contributes to accomplishing
the entity's purpose. Strong cohesion is a high degree of internal relatedness of elements. With strong
cohesion there are no "out of place" elements. All elements contribute to the entity's purpose. Weak


OO Modeling with WithClass - Microgold Software Inc. www.microgold.com
                                                                                                            9
cohesion is a low degree of internal relatedness of elements. With weak cohesion there are elements that
are "out of place" and that do not contribute the entity's purpose.


In the physical world an example of strong cohesion is a highly trained medical hospital emergency room
team as shown in the figure below. All its members, for example doctors, nurses, orderlies, etc. all work
together to contribute to the organization's purpose to provide excellent medical care. There are no "out
of place" members. We would say the hospital emergency room team is "highly cohesive". In software a
bank account object has strong cohesion if all its elements (attributes and operations) support the
object's purpose. There are no "out of place" attributes or operations.




Figure 1.9. Strong cohesion in an emergency room team.


An example of weak cohesion is a poorly managed government drivers' license bureau. All its elements,
such as managers, clerks, secretaries, etc. do not all work together. Members are "standing around" and
"out of place". In software an object has weak cohesion if it has elements, for example attributes and
operations that don't support the object's purpose. There are attributes and operations that are "out
of place".


Two other techniques to achieve software quality factors are the use of aggregation ("part of"
relationship) with the propagation of operations and subclasses ("is a" relationship) with polymorphic
operations. These techniques will be presented in the chapter dealing with relationships.


OBJECT-ORIENTED METHODOLOGIES


An object-oriented methodology has a defined set of entities (system, class, object, etc.), graphic
symbols, diagrams, forms, rules, and procedures. It is a process that generally covers the entire software
lifecycle from requirements to implementation. Many WithClass tool supports a subset graphic notation
for several object-oriented methodologies, e.g. Rumbaugh Object Modeling Technique (OMT),
Coad/Yourdon Object-Oriented Analysis and Design (OOA/OOD), Booch Object-Oriented Design (OOD),
and Shlaer Mellor OOA/OOD. The following is a very brief overview of these methodologies.


Rumbaugh Object Modeling Technique (OMT)


This OO methodology is documented in Object-Oriented Modeling and Design by James Rumbaugh et. al
[Rumbaugh-91]. It has a strong data modeling origin. It has a very comprehensive graphic notation.
Analysis in OMT consists of the Object Model, Dynamic Model, and Functional Model which will be
described shortly. Analysis is followed by system design and detailed design. OO Modeling presented in
this tutorial covers the OMT Analysis Model.



OO Modeling with WithClass - Microgold Software Inc. www.microgold.com
                                                                                                         10
Inputs Analysis System Detailed Design

Model Design Model Model



--> --> -->
System Object Model System - Detailed Object Model


Require Dynamic Model Subsystem Detailed Dynamic Model


ments Functional Architecture Detailed Functional


Model Model


Coad-Yourdon Object-Oriented Analysis and Design (OOA/OOD)


This OO methodology is documented in Object-Oriented Analysis and Object-Oriented Design by Peter
Coad and Ed Yourdon [Coad-91a and Coad-91b]. It has a strong data modeling origin. It has a simple
graphic notation. OOA consists of identifying and organizing classes from different points of view called
layers. OOD consists of refining the OOA model for the human interface, problem domain, data
management, and concurrent task management.


Booch Object-Oriented Design (OOD)


This OO methodology is documented in Object-Oriented Design with Applications by Grady Booch
[Booch-94]. It has a very strong real-time and message passing origin. It has an extensive,
comprehensive graphic notation. OOD consists of modeling a system by identifying, organizing,
and specifying subsystems, classes, objects, implementation modules and processes.


Fusion Object-Oriented Development (OOD)


This OO methodology is documented in Object-oriented Development The Fusion Method by Derek
Coleman et al [Coleman-93]. The Fusion Method consists of an analysis phase and a design phase.
Analysis has the object model and interface model. Design has the object interaction graph, visibility
graph, inheritance graph, and class description.


Shlaer-Mellor Object-Oriented Analysis and Design (OOA/OOD)


This OO methodology is documented in Object Lifecycles - Modeling the World in States by Sally Shlaer
and Stephen Mellor [Shlaer-92]. OOA consists of information (data) models, state models, and process
models similar to the OMT object model, dynamic model, and functional model. OOD consists of refining



OO Modeling with WithClass - Microgold Software Inc. www.microgold.com
                                                                                                            11
the OOA models for an implementation environment.


In this tutorial we will use the Object Modeling Technique (OMT). OMT supports the entire software
development lifecycle from requirements to implementation source code. However, we will only cover
the early portion of the software lifecycle. In OO modeling in this tutorial, we will identify, organize, and
prototype initial classes and objects in a system. We will not discuss specifics of system design or
detailed design. In this tutorial select Rumbaugh OMT from the WithClass tool methodology menu.


SUMMARY


OO modeling is a process to describe systems. A system is an independent entity that consists of classes,
objects, and relationships. It is an important process for the development of OO systems with OO
languages, such as C++. WithClass is useful to create OO diagrams, text specifications, code generation,
and reverse engineering of diagrams from code. WithClass from MicroGold Software is a highly capable
CASE tool with a scripting language.


Please email all comments and questions to techsales@microgold.com




OO Modeling with WithClass - Microgold Software Inc. www.microgold.com
                                                                                                            12

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:8
posted:6/19/2011
language:English
pages:12