Lecture 1 :
Introduction
Outline
• Software Development Process
• Object-Oriented Approach
• Encapsulation
1
Software Development Process
Problem
Analysis
Object
Orientation
Design
Documentation
Implementation
(C++)
Product
Testing
1.3
Software Development Process
ANALYSIS: Understanding the requirements.
DESIGN: Identifying the entities.
In object-oriented design, entities are objects.
CODING: Implementation in a programming language.
DOCUMENTATION: Writing reports for development team.
Also a users manual should be written.
TESTING: The functions of each object and the whole program
must be tested for possible inputs and expected outputs.
1.4
2
Unified Process Method
in Software Development
A software development process describes an approach to
building, deploying, and maintaining a software.
The Unified Process is a popular iterative software
development process for building object-oriented
systems.
Development is organized into a series of mini-projects
called iterations.
Each iteration includes its own analysis, design,
implementation, and testing activities.
1.5
The Unified Process (UP)
Requirements Requirements
Analysis Analysis
Next time Design
Design
Implement Implement
Test Test
Product1 Product2
An iteration has a
fixed time
(Example: 3 weeks)
1.6
3
User view
A program must have the following features:
• Runs correctly.
• Runs reliably.
• Performs as fast as necessary.
• Does not waste system resources too much.
(Processor time, Memory, Disk).
• Easy to upgrade the program (re-installation).
• Have sufficient documentation of users manuals.
1.7
Software developer view
A program must have the following features:
• Source code must be readable and understandable.
• It must be easy to maintain and update (change) the program,
according to new requirements.
• An error should not affect other parts of a program.
• Modules of program must be reusable in further projects.
• It must have sufficient design documentation.
1.8
4
Programming Process
Program development is based on models of real world situations.
Computer programs are the implementions of models.
Modelling is the design of a software.
• UML diagrams can be used for design of classes.
• Flowcharts can be used for design of algorithms.
Implementation (Coding):
A programming language such as C++ is used for the implementation.
1.9
Advantages of C++
• C++ supports object-orientation and generic programming
(templates).
• Speed of programs written with C++ is high.
• C++ is supported by many standard built-in program libraries.
• C++ programmers can easily adapt to other object oriented
programming languages such as Java or C#.
1.10
5
Some Application Domains of C++
Banking,trading,insurance: Maintainability, ease of
extension, reliability.
Systems programming: Operating systems, device drivers.
(Direct usage of hardware under real-time constraints.)
Graphical User Interface (GUI) programs
Computer communication programs
1.11
An Obsolete Technique:
Procedural Programming
• In a procedural language such as C or Fortran, the emphasis is on
functions, not objects.
• A program is divided into functions.
Main program Functions
Shared global data
1.12
6
Disadvantages of Procedural Programming
• Data is less emphasized, functions are more emphasized.
• Procedural programs don’t model the real world very well.
The real world does not consist of functions.
• To add new data items, all the functions that access the
data must be modified, so that they can access the new items.
1.13
The Object-Oriented Approach
The fundamental idea behind object-oriented programming is:
• The real world consists of objects.
Thinking in terms of objects, rather than functions, makes the
design easier.
To solve a programming problem in an object-oriented language,
the programmer asks how the problem will be divided into
objects.
A problem will be easier to understand and handle, if you organize
things as objects.
1.14
7
Advantages of
Object-oriented programming
Readability
Understandability
Low probability of errors
Easy maintenance
Reusability
Teamwork
1.15
Example : University System
A University System may contain the following entities
(objects):
Students have a number, courses attended.
They take grades, their GPAs are calculated.
Instructors give courses, they perform some projects,
they have administrative duties.
Courses are given in specific times in a classroom.
They have a plan, they have a list of students.
1.16
8
The Object-Oriented Approach
Real world objects have two parts:
1. Attributes (DATA)
2. Methods (FUNCTIONS)
Some examples of objects:
• Graphics program: Point, Line, Square, Circle, etc.
• Mathematics: Complex numbers, Matrix
• Graphical user interface: Windows, Menus, Buttons
• Data structures: Arrays, Stacks, Linked lists
1.17
Encapsulation (Classes)
To create software models of real world objects, both data and
functions are combined into a single program entity (CLASS).
Data and its functions are said to be encapsulated into a single
entity.
The data of an object can be private, so it cannot be accessed
directly. The data can only be changed through its functions
(also known as its public interface).
Classes simplify writing, debugging, and maintaining the program.
1.18
9
The Model of an Object
In object-oriented programming, objects combine data and
functions.
A C++ program consists of a number of objects that communicate
with each other by calling member functions.
Class diagram
for Point object Data
(attributes)
hide
x print
y
Functions
move (methods)
1.19
Structure of an object-oriented program
Messages are member functions of an object with necessary
parameter values.
Objects
Main
program
message1 message4
message2 message5
message3
1.20
10
Example:
Point class in a graphics program
The Point class can be defined with following members.
integer variables (x,y) : Coordinates of a point.
move() function: Moves the point to a new x,y coordinate.
print() function: Displays the point on screen.
hide() function: Disappears the point on screen.
1.21
Example : Point class and objects
First, the class declaration of Point should be written.
Then, objects (variables) of the class can be defined in main
program.
Point is the class
class Point { declaration.
int x, y;
public:
void move(int, int); point1, point2, and
void print(); point3 are the objects
void hide(); (variables , instances) of
}; the Point class.
int main() {
Point point1, point2, point3; //Declare three objects
point1.move(50, 30); //Goto coordinate 50, 30
point1.print(); //Display the point
point1.hide(); //Disappear the point
}
1.22
11