Académique Documents
Professionnel Documents
Culture Documents
UCS 4045 :
UNIT I
Limitations in structured programming-Characteristics of Object
Oriented Language data types loops pointers arrays structures
functions Classes Objects.
UNIT II
Operator overloading Inheritance Polymorphism Templates
Exception Handling class Hierarchies library organization and
containers Strings Stream Design and programming.
UNIT III
Object Orientation System development Review of objects inheritance - Object relationship Dynamic binding OOSD life cycle
Process Analysis Design prototyping Implementation TestingOverview of Methodologies.
UNIT IV
OMT Booch methodology, Jacobson methodology patterns Unified
approach UML Class diagram Dynamic modeling. Use case model
Creation of classes Noun phrase approach responsibilities
Collaborators Object relationships Super-Sub class Aggregation.
UNIT V
OO Design axioms Class visibility refining attributes Methods
Access layer OODBMS Table class mapping view layer. Quality
assurance testing - Inheritance and testing Test plan Usability testing
User satisfaction Testing.
Note: Unit I & II deals with C++
TEXT BOOKS
1.
2.
UNIT I
Limitations
in
structured
programming-
1.Objects
2.Classes
3.Data abstraction and encapsulation
4.Inheritance
5.Polymorphism
6.Dynamic binding
7.Message passing
OBJECTS
1.Explicit representation
2.Implicit/internal representation
EXPLICIT REPRESENTATION
Object: STUDENT
DATA
Name
Date of
birth
Marks
..
FUNCTIONS
Total
Average
Display
.
IMPLICIT REPRESENTATION
Here data declaration and definition are hided .It has only what are the
functions that can be implemented.
CLASSES
Total
STUDENT
single entity. Once a class has been defined we can create any number of
objects belonging to that class. And using these objects we can access
the class.
Display
For example, mango, apple and orange are the members of a class Fruit.
Now the object mango can be created as:
Fruit mango;
INHERITANCE
Class a
{
add();
//parent class
mul();
};
Class b : : public a
//derived class
{
add();
fact();
};
POLYMORPHISM
1. Function overloading
Using a single function name to perform different type of tasks
is called function overloading. Here many functions may have the same
name, but have different set of parameters.
Example:
void add(int , int);
float add(float, float);
double add(double, double);
2. Operator overloading
The operator can be made to exhibit different behaviors in
different instances. For example the + operator can be used to add
integer numbers and the same operator can be used to concatenate two
strings.
Example:
i.
2+5=7
ii.
DYNAMIC BINDING
Static binding
Dynamic binding
Dynamic binding means that the code associated with a procedure call is
not known until the time of call at runtime.It is associated with
polymorphism and inheritance.
MESSAGE PASSING
ii.
iii.
E.g.:
Employee. Salary (name);
(object) (message)
(information)
DATA TYPES
Both C and C++ compilers support all the built-in data types.
1. User-defined type
i. Structure
ii. Union
iii. Class
iv. Enumeration
2. Built-in type
i. Integral type
a. int
b. char
ii. Void
iii. Floating type
a. float
b. double
3. Derived type
i. Array
ii. Function
iii. Pointer
iv. Reference
CONTROL STATEMENTS
1. Conditional statements
if statement
if else statement
switch case statement
2. Loop statements
for loop
while loop
do while loop
3. Breaking control statements
break statement
continue statement
goto statement
CONDITIONAL STATEMENTS
The conditional expressions are mainly used for decision making.
SIMPLE IF:
The if statement is used to express conditional expressions.
Syntax:
if ( test expression )
{
statement block;
}
statement x;
IF ELSE STATEMENTS:
The if else statement is an extension of the simple if statement
Syntax:
if ( test expression )
{
true block statement(s);
}
else
{
false block statement(s);
}
statement x;
SWITCH STATEMENT:
The switch statement tests the value of a given variable (or
expression) against a list of case values and when a match is found, a
block of statements associated with that case is executed.
Syntax:
switch ( expression )
{
case value_1:
block_1
break;
case value_2:
block_2
break;
default:
default_ block
break;
}
statement x;
..
..
index = marks/10;
switch (index)
{
case 10:
case 9:
case 8:
grade=HONOURS;
break;
case 7:
case 6:
grade=FIRST DIVISION;
break;
case 5:
grade=SECOND DIVISION;
break;
case 4:
grade=THIRD DIVISION;
break;
default:
grade=FAIL;
break;
}
cout<<grade;
LOOP STATEMENTS
They
are
essential
to
construct
systematic
block
styled
programming.
FOR LOOP:
The for loop is an entry controlled
( ii )
Example:
for( x=1; x<=10; x++)
{
cout<<x;
}
Initially, x value is 1and the condition is checked. As the condition is
true, the control enters the loop and prints the value of x ( i.e. 1 ). Now x
value is incremented by one and the condition is checked. Similarly the
loop is executed 10 times and finally the value of x reaches 11 and is
checked. As the condition fails the control comes out of the loop.
WHILE STATEMENT:
The simplest of all structures in C++ is the while statement.
Syntax:
while ( test condition )
{
Body of the loop
}
The test condition is executed and if the condition is true, then the body
of the loop is executed. After execution of the body, the test condition is
once again evaluated if it is true. This process of execution repeatedly
continues until the test condition becomes false and the control is
transferred out of the loop.
Example:
..
sum=0;
n=1;
while ( n<= 10 )
{
sum = sum + n * n;
n = n +1;
}
cout<<SUM= <<sum;
..
The body of the loop is executed ten times for n = 1, 2, . ,10 each time
adding the square of the value of n, which is incremented inside the loop.
n is called counter or counter variable.
DO WHILE STATEMENT:
Example:
do
{
cout<<INPUT A NUMBER\n;
number = getnum();
}
while (number > 0);
This segment of program reads a number from the keyboard until a zero
or a negative number is keyed in, and assigned to the sentinel variable
number.
BREAK STATEMENT:
When a break statement is encountered inside a loop, the loop is
immediately exited and the program continues with the statement
immediately following the loop. When the loops are nested, the break
would only exit from the loop containing it. That is, the loop will exit only
a single loop.
1.
while ( )
2.
do
{
.
..
if ( condition )
if( condition
break;
break;
3.
...
}while ( .. );
for ( . )
4.
for ( . )
{
.
if ( error )
for ( )
break;
if( condition
...
break;
.
}
.
}
GOTO STATEMENT:
Since a goto statement can transfer the control to any place in a
program, it is useful to provide branching within a loop. Another
important use of goto is to exit from deeply nested loops when an error
occurs. A simple break statement would not work here.
UNCONDITIONAL GOTO:
The unconditional goto is used to transfer the control from
one part of the program to the other part of the without checking any
condition.
Consider,
#include<iostream.h>
{
start:
cout<<MY NAME IS SWERISH\n;
goto start;
CONDITIONAL GOTO:
The conditional goto is used to transfer the control of the
execution from one part of the program to the other in conditional cases.
1.
while ( )
2.
for ( .. )
if ( error )
goto stop;
for ( )
if ( condition )
..
goto abc;
if ( error )
goto error;
abc:
..
stop:
error:
CONTINUE STATEMENT:
During the loop operation, it may be necessary to skip a part of the
body of the loop under certain conditions. However, unlike the break
which causes the loop to be terminated, the continue, as the name
implies, causes the loop to be continued with the next iteration after
skipping any statements in between continue statement and closing
braces.
1.
2.
do
{
if ( )
if ( .. )
continue;
continue;
}
while ( test condition );
3.
for ( . )
{
.
if ( .. )
continue;
.
}
CONTROL STRUCTURE
Multiple branch
Entry SELECTION
control
IF ELSE
Exit control
SEQUENCE
SWITCH
LOOP
DO-WHILE
WHILE, FOR
POINTERS
A pointer is a variable which holds the memory address of another
variable. In terms of pointer, only complex data type can be declared and
accessed easily.
ADVANTAGES
1. It
allows
passing
variables,
arrays,
functions,
strings
and
POINTER OPERATOR
ptr -> pointer variable which holds the address of an integer data type.
Format:
ADDRESS OPERATOR
& -> is a unary operator that returns the memory address of its operand.
A unary operator requires only one operand.
Eg:
m=&ptr;
m receives the address of ptr.
POINTER EXPRESSIONS
Pointer assignment:
Eg:
int x,y;
int *ptr1,*ptr2;
ptr1=&x;
y=*ptr1;
#include<iostream.h>
void main()
{
char x,y;
char *ptr;
x=c;
ptr=&x;
y=*ptr;
cout<<x;
cout<<y;
}
POINTERS TO FUNCTIONS
#include<iostream.h>
void main()
{
float average(float,float,float); //function declaration
float a,b,c,avg;
float (*ptrf) (float,float,float); //pointer to function declaration
ptrf=&average;
cout<<enter three numbers;
cin>>a>>b>>c;
avg=(*ptrf) (a,b,c); //function calling using pointer
cout<<a= <<a;
cout<<endl<<b= <<b;
cout<<endl<<c= <<c;
}
float average (float x,float y,float z)
{
float temp;
temp=(x+y+z)/3.0;
return (temp);
}
Syntax:
#include<iostream.h>
void main()
{
float add(float,float); //function declaration
float sub(float,float);
float action(float(*)(float,float), float,float);
float (*ptrf)(float,float);//pointer to function declaration
float a,b,value;
char ch;
cout<<Enter any two numbers;
cin>>a>>b;
cout<<a->addition;
cout<<s->subtraction;
cout<<Entet your option;
cin>>ch;
if(ch= =a)
ptrf=&add;
else
ptrf=⊂
cout<<a=<<a;
cout<<b=<<b;
value=action(ptrf,a,b);
cout<<answer=<<value;
}
float add(float x,float y)
{
float ans;
ans=x+y;
return(ans);
}
float sub(float x,float y)
{
float ans;
ans=x-y;
return(ans);
}
float action(float (*ptrf) (float,float),float x,float y);
{
float answer;
answer=(*ptrf)(x,y);
return(answer);
}
datatype array_name[size];
datatype ptr_variable;
Eg:
int value[20];
int *ptr;
ptr=&value[0];
.
.
ptr=&value[n];
value[i]=*((value)+(i));
It can also be given as
value[i]=*(&(value)[10] + (i));
#include<iostream.h>
void main()
{
int a[4]={11,12,13,14};
int i,n,temp;
n=4;
cout<<Contents of the array:;
for(i=0;i<n;i++)
{
temp=*((a)+(i));
cout<<Value=<<temp;
}
}
#include<iostream.h>
void main()
{
int a[2][3]={11,12,13,14,15,16};
int i,n,temp,j,m;
int *ptr;
n=2;
m=3;
cout<<Contents of the array:;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
temp=*(*(a+i)+(j));
cout<<Value=<<temp;
}
}
}
#include<iostream.h>
#define MAX 50
void main()
{
char s[MAX];
void output(char *s);
cout<<Enter the string:;
cin.get(s,MAX);
cout<<OUTPUT;
output(s);
}
void output(char *ptr)
{
while(*ptr!=\0)
{
cout<<*ptr;
ptr++;
}
}
ARRAY OF POINTERS
Pointers may be array like any other datatype. The declaration for an
integer pointer array of size 10 is :
int *ptr[10];
makes
ptr[0],ptr[1]ptr[9]
#include<iostream.h>
void main(void)
{
char *ptr[2];
ptr[0]=Rajiv;
ptr[1]=Arun;
cout<<Contents of pointer1=<<ptr[0];
cout<<Contents of pointer2=<<ptr[1];
}
POINTERS TO OBJECTS
(*ptr).get();
Eg:
student *s;
POINTER ARITHMETIC
Pointer arithmetic
ptr++
Description
ptr=ptr+size of datatype
Use original value of ptr and then ptr is incremented
++ptr
ptr--
this statement.
ptr=ptr-size of datatype
Use
--ptr
original
value
of
ptr
and
then
ptr
is
*(ptr++)
the statement.
*(ptr++).
Retrieve the content of the location pointed to by the
*(++ptr)
(*ptr)++
++(*ptr)
--(*ptr)
*(ptr--)
*(--ptr)
(*ptr)--
ARRAY DECLARATION:
Syntax:
Datatype specifies the type of data that the array can hold.
Arrayname can be any variable name. The size of the array specifies how
many data items the array can hold and it should be a constant or an
expression that evaluates to a constant.
ARRAY INITIALIZATION:
SYNTAX:
Datatype arrayname [size] = { element 1,
Element 2.. element
n};
Eg:
#include<iostream.h>
void main()
{
int a[7]= { 2,5,6,8,9,10,11 };
int i;
for(i=0;i<7;i++)
cout<<a[i];
}
The array argument uses the datatype as name and the sizes
of the dimensions . All the array dimensions must be specified.
Eg : void sum(int x[ ],int max)
with
more
than
one
Syntax:
CHARACTRER ARRAY:
It is a group of characters or strings that can be
declared with array name.
Syntax :
Datatype arrayname [size of array ];
#include<iostream.h>
void main()
{
int i;
char name[6]={ h,e,l,l,o};
for(i=0;i<=5;i++)
cout<<Name<<name[i];
}
STRUCTURES
Its a collection of hetrogenous datatype that can be grouped to form a
structure.so the entire collection can be referred to by a structure name.
structure
can
be
graphically
represented
as
name
member 1
member 2
member 3
member n
given
SYNTAX:
struct username/structure name
{
member 1; --> variables
member 2;
member 3;
.
.
member n;
};
tagname.variable name=value;
eg. Today.day=10;
#include<iostream.h>
#include<conio.h>
void main()
{
struct sample
{
int x;
float y;
};
struct sample a;
a.x=10;
a.y=20.0;
cout<<a.x<<a.y;
}
INITIALIZATION OF A STRUCTURE:
Syntax:
structurename tagname= { values };
#include<iostream.h>
void main()
{
struct name
{
int roll no;
int age;
char sex;
float weight;
};
school student={130,19,F,50};
cout<<Rollno:<<student.rollno;
cout<<Age<<student.sge;
cout<<sex:<<student.sex;
cout<<weight<<student.weight;
}
Syntax:
int salary:
};
here the c++ compiler will assign the values to its members of a structure
as
student[0].age=10;
student[0].salary=10000;
student[1].age=20;
student[1].salary=15000;
FUNCTIONS:
A complex problem may be decomposed into a small or easily
manageable parts or modules called functions. Functions are useful to
read, write, debug and modify complex programs.
ADVANTAGES OF FUNCTIONS:
e.g.
Eg:
add(a,b);
Eg:
add(a,b);
a and b are called actual arguments.
LOCAL VARIABLES:
GLOBAL VARIABLES:
RECURSIVE FUNCTION:
void main( )
{
-----------return( 0);
}
Most c++ compilers would generate an error or warning if there is no
return statement.
FUNCTION PROTOTYPING:
Function
prototype
is
declaration
statement
Syntax:
CALL BY VALUE:
In the function call if we are using the name of
the variable then it is called as call by value method.
CALL BY REFERENCE:
When we pass arguments by reference ,
the formal arguments in the function called aliases to the actual
arguments in the calling function. This means that when the function is
working with is own arguments it is actually working on the original
data.
RETURN BY REFERENCE:
A function can also return a reference
value. Consider the following example
INLINE FUNCTION:
An inline function are defined as follows
c=cube ( 3.0 );
d= cube ( 2.5+1.5);
NOTE:
ignore the keyword inline and it will make the function as normal
function.
DEFAULT ARGUMENT:
Default values are specified where the
function is declared .
Eg
FUNCTION OVERLOADING:
Overloading refers to the use of the same
thing for different purpose . c++ allows function overloading. This means
we can use same function name to create functions that perform
different tasks. This is known as function overloading.
Using this concept we can design a family
of function with one function name but with different argument list. The
function would perform different operations depending on the argument
list in the function call.
The function that is to be invoked is determined by checking the
number and types of arguments but not the function type. The function
selction involves the following steps.
1. The compiler first tries to find an exact match in which the types of
actual arguments are the same and use that function.
conversion to the actual arguments and then uses the function whose
match is unique. If the conversion is possible to have multiple matches,
then the compiler will generate an error message. For example
long square ( long n )
double square ( double x )
when the function call is square(10);
It will cause an error because int argument can be converted to either
long or double , thereby creating an ambiguous situation as to which
version of square() should be used.
3. If all steps fails then user defined conversions is done and it is a
combination with integral promotions and built in conversions.
Eg :
Function declarations
int add ( int a, int b);
//prototype 1
int add ( int a, int b , int c );
//prototype 2
double
add
(double
x,double
);
//prototype 3
double add (int p,double q ); //prototype
4
Function calls
cout<<add(5,10)
1
//prototype
cout<<add(15,10.0);
//prototype 2
cout<<add(12.5,6.5);
cout<<add(5,10.1);
//prototype 3
//prototype4
FRIEND FUNCTION:
The main concepts of oop are data hiding and
data encapsulation. That is we are declaring variables in private part of a
class. So these members are restricted from accessing by non member
functions of the class. If any of the non member functions tries ti access
the members of the class , then a error messege is displayed .so for a non
member functions to have access to the members of the class they
should be declared in the public area which violates the data hiding and
encapsulation.
So the best way to access a private data member by a
non member functions is to declare a friend function to have access to
these data members.
Friend function:
It is a special mechanism of giving or granting
permission to non member functions to have access to private data.
Syntax:
NOTE:
1. friend function can be declared either in the private part or in the
public part of a class.
2.The keyword friend should be specified only in the function
declaration and it should not be specified in the function definition.
Ex:
Friend function disp() is declared in the public part
class first
{
private:
int x;
public:
void get();
friend void disp();
};
the friend function disp() is declared in the private part of the class.
class second
{
private:
int x;
Example:
#include<iostream.h>
class sample
{
private:
int x;
public:
void get();
friend void disp(class sample);
};
void sample :: get()
{
cout<Enter the value for x;
cin>>x;
}
void disp(class sample abc)
{
cout<Entered numbers are<<abc.x;
cout<<end l;
}
void main()
{
sample obj;
obj.get();
cout<<Accessing the private data by non member function;
}
#include<iostream.h>
class first
//Friend class
{
friend class econd;
private:
int x;
public:
void get();
};
class second
{
public:
void disp( first temp);
};
inline void first ::getdata()
{
cout<<Enter a number;
cin>>x;
}
inline void second :: disp( class first temp)
{
cout<<Entered numbers are :<<temp.x;
cout<<endl;
}
void main()
{
first objx;
second objy;
objx.get();
objy.disp(objx);
}
Syntax for declaring friend function with more than one class:
class first
{
private:
-----------public:
friend return type fname (class first , class second);
};
class second
{
private:
-----------public:
friend return type fname (class first , class second);
};
CLASSES:
A class is a collection of objects of similar type. That is it is a
collection of variables of different datatypes and the functions that act on
them into a single entity. Once a class has been defined we can create
any number of objects belonging to that class. And using these objects
we can access the class.
For example, mango, apple and orange are the members of a class Fruit.
Now the object mango can be created as:
Fruit mango;
CLASSES:
*The most important feature of C++ is the class.
*They are similar to the structures used in C with some additional
features.
*It is a new way of creating and implanting a user_defined data type.
DEFINITION
*A class is a user defined data type,which holds both the data and
functions.
*The internal data of a class is called member data or data member.
*The functions are called member functions.
SPECIFYING A CLASS
*When defining a class, we are creating a new abstract data type ,that
can be treated
like any other any other built_in data type.
*A class specification has two parts,namely,
i)Class declaration
ii)Class function definition
CLASS DECLARATION
*It is better to declare,
*Members in private part.
*Member functions in public part.
*In classes variables that are declared, are by default private.
GENERAL FORM
Class class_name
{
Private:
Variable declarations;
Public:
Function declarations;
Protected:
Data_type operations;
Implementation operations;
};
PRIVATE
*The class members that have been declared private can be accessed
only from within the class.
*(ie)Only by the member functions and friend functions of the class.
*The private data member is not accessible to the outside class.
PUBLIC:
*The members which are declared in the public section can be accessed
by any function outside the class.
*The member functions can also be accessed outside the class.
*The public implemented operations are also be called as member
functions or methods or interfaces to out of the class.
*The public data members can always read and write outside the class.
PROTECTED
*The members which are declared in the protected part,can only be
accessed by the member functions and friend functions of the class.
OBJECTS:
*It is an instance of class.
*It is similar to variables.
*We can declare variables in the same way as buil_in type.
DECLARING VARIABLES
*A variable can be declared as follows:
SYNTAX
class name/userdefined name object name
Eg:
Class student
{
.
.
.
.
};
Student s1,s2,s3;
*In this above example,student is a class,in which s1,s2,s3 are the
objects that are created.
s.putdata();
*s.putdata() sends a message to the object s,requesting it to display its
contents.
membership
label
tells
the
compiler
that
the
EXAMPLE:
*A program to add two numbers using classes and objects.
#include<iostream.h>
#include<conio.h>
class addition
{
private:
int a,b,c;
public:
void add();
void display();
function
};
void addition::add()
{
cin>>a>>b;
c=a+b;
}
void additin::display()
{
cout<<c;
}
void main()
{
addition a1;
a1.add();
a1.display();
}
{
public:
int a,b,c;
void add()
{
cin>>a>>b;
c=a+b;
}
void display()
{
cout<<c;
}
};
void main()
{
addition a1;
a1.add();
a1.display();
}
{
int n,m;
public:
largest();
get();
display();
};
get()
{
cin>>n>>m;
}
largest()
{
int large;
if(n>m)
large=n;
else
large=m;
cout<<largest<<large;
}
display()
{
largest();
}
main()
{
ABC a;
a.get();
a.display();
}
ARRAYS OF OBJECTS
*If there are many objects,then we can use arrays of objects.
*An array is an user defined data type,whose members are of the same
type and stored in continous memory locations.
SYNTAX
*The general form is,
class user_defined name
{
private:
//data members;
public:
//member functions();
};
class user_defined name object[max];
*In this example,MAX is a user_defined size of the array of classes
*The following are the various types of declaration of an array of objects
i)const int max=100
class employee
{
private:
public:
...
.
};
Class employee obj[max];
*In this example,the class employee has been declared as an object of
size 100.
ii)class library
{
private:
public:
..
..
}object[100];
*Here, we have declared the array of objects in the class definition itself.
iii)A classs can be declared without defining a user_defined name in the
class tag.
class
{
private:
.
public:
..
.
}library[100];
E XAMPLE PROGRAM
*A
program
to
read
students
particulars
such
as
{
cout<<rollno;
cout<<age;
cout<<sex;
cout<<height;
cout<<weight;
}
};
void main()
{
student object[max]; //array of objects
int n;
cin>>n;
for(i=0;i<n;i++)
{
int j=i;
cout<<j+1;Object[i].getinfo();
}
cout<<contents of class;
for(i=0;i<n;i++)
{
object[i].disinfo();
}
}
DECLARATIONS
*It can be done in two ways:
i)
class student
{
private:
public:
.
.
};
void main()
{
student *ptr;
.
.
(*ptr).data member;
(*ptr).member function();
}
ii)
class student
{
private:
.
public:
..
..
};
void main()
{
student *ptr;
ptr->data member;
ptr->member_function();
}
ACCESSING POINTERS
*The pointer to an object of a class will be accessed and processed in one
of the following ways:
i)(object name).member name=variable
*Here the parenthesis are essential,since,the member of class period (.)
has a higher precedence over the indirecton operator(*).
ii)object name->member name =variable;
EXAMPLE PROGRAM
*A program to assign some values to the member of claa objects using a
pointer operator,
->
#include<iostream.h>
#include<conio.h>
class student
{
private:
long int rollno;
int age;
char sex;
float height;
float weight;
public:
void getinfo();
void disinfo();
};
void student::getinfo()
{
cin>>rollno;
cin>>age;
cin>>sex;
cin>>height;
cin>weight;
}
void student::disinfo()
{
cout<<rollno;
cout<<age;
cout<<sex;
cout<<height;
cout<<weight;
}
void main()
{
student *ptr;
ptr->getinfo();
ptr->disinfo();
}
EXAMPLE PROGRAM
(*ptr).getinfo();
(*ptr).disinfo();
}
EXAMPLE PROGRAM
*A program to define a nested class student,which contains data
members such as name,rollno,sex and consists of one more class
data,whose data members are day,month and year.
#include<iostream.h>
#include<string.h>
class student_info
{
private:
char name[20];
int rollno;
char sex;
public:
student_info(char *no,int rn,char sx);
void display();
class date
{
private:
int day;
int month;
int year;
public:
date(int dy,int mh,int yr);
void show_date();
}:
};
{
student_info obj1(abc,1000,m);
student_info::date obj2(13,7,94);
obj1.display();
obj2.show_date();
}
CONSTRUCTORS:
A constructor is a special member function whose task is to
initialize the objects of its class. Whenever an object is created, the
constructor will be executed automatically. A constructor is different
from all the other member functions of a class because it is used to
initialize the objects of the class.
Syntax:
The general syntax of a constructor in C++
class user_name
{
private :
..
..
protected:
..
..
public:
user_name(); //constructor declaration
};
user_name::user_name()
//constructor definition
{
..
.
..
}
Examples:
class employee
{
private:
char name[20];
int ecode;
char address[20];
public:
employee();
//constructor
void getdata();
void display();
};
employee::employee() //constructor definition
}
In the class employee, it contains a constructor. The name of the
constructor is the same as the name of the class, so the name of the
constructor here is also employee.
Now, if we create an object for the class employee, it will be
initialized automatically.
For example ,the declaration
employee e1; //object e1 is created.
This statement not only creates the object e1 of type employee but
also initializes the data members.
There is no need to invoke a constructor like other member
functions of the class.
Default constructor:
A constructor that accepts no parametersis called the
default constructor.
The default for this
class abc
other
C++
functions,
constructor
can
have
default
arguments.
6. constructors cannot be virtual.
7. we cannot refer to their addresses.
8. an object with a constructor (destructor) cannot be used as a
member of a union.
9. they make implicit calls to the operators new and delete when
memory allocation is required.
#include<iostream.h>
#include<conio.h>
class Fibonacci
{
private:
unsigned long int f0,f1,fib;
public:
Fibonacci();
//constructor
void increment();
void display();
};
Fibonacci::Fibonacci()
{
f0=f1;
f1=fib;
fib=f0+f1;
}
void fibonacci :: display()
{
cout<<fib<<\t;
}
void main()
{
fibonacci number;
for(int i=0;i<=15;i++)
{
number.display();
number.increment();
}
}
Parameterized constructor:
//constructor
//constructor declared
};
integer :: integer(void)
//constructor definition
{
m=0;n=0;
}
when objects are declared or created for the class integer, the
constructor initializes all the objects to zero.
//parameterized
constructor
};
integer::integer(int x, int y)
{
m=x;
n=y;
}
Now the constructor integer (), is parameterized.
//implicit
call.
This method is used often.
When a constructor is parameterized, we must provide appropriate
arguments for the constructor.
//constructor declared
void display()
{
cout<<m= <<m;
cout<<n= <<n;
}
};
integer :: integer (int x, int y)
//constructor defined
{
m=x;
n=y;
}
void main()
{
integer i1(0,100); //implicit call
integer i2=integer(25,75);
cout<<object;
i1.display();
cout<<object2;
//explicit call
i2.display();
}
};
Note:
1. in a parameterized constructor, the parameters can be of any type,
except the class, to which the constructor belongs.
Ex:
class a
{
..
..
public:
a(a);
};
this is illegal because, the class a is passed as argument.
2. a constructor can accept a reference to its own class as a
parameter.
3. ex:
class a
{
public:
a(a&);
};
this is valid.
constructor.
//constructor1
{
m=0;
n=0;
}
integer(int a, int b)
{
m=a;
//constructor2
n=b;
}
integer(integer &i)
{
m=i.m;
n=i.n;
}
};
//constructor3
Such
constructor
is
called
copy
constructor,
the
third
Constructor overloading:
In the above program, more than one constructor
function is defined in a class, the constructor is overloaded.
The
above
overloading.
The
program
is
constructor
an
example
function
for
integer(),
constructor
does
three
for
the
constructor
here.
Hence
the
integer
()
constructor is overloaded.
Copy constructors:
Copy constructors are always used when the compiler
has to create a temporary object of the class.
The copy constructors are used in the following situations:
(i1);
i2
integer
i2=i1;
The process of initialization through
a copy constructor is known as copy initialization.
#include<iostream.h>
class code
{
int id;
public:
code ();
//constructor
code(int a)
//constructor
{
id=a;
}
code(code &x)
{
id=x.id;
}
void display(void)
{
cout<<id;
//constructor
}
};
main()
{
code a(100);
code b(a);
code c=a;
d=a;
assigned to d
cout<<id of a:<<a.display();
cout <<id of b:<<b.display();
cout <<id of c:<<c.display();
cout <<id of d:<<d.display();
}
OUTPUT
Id of a:100
Id of b:100
Id of c:100
Id of d:100
In the declaration of the copy constructor
Copy (code &x)
Note, a reference variable has been used in the argument to the copy
constructor.
Note:
It is important to distinguish between default argument a::a() and
the default argument constructor a::a(int
DESTRUCTORS :
name of the destructor is the same name as the class name, but it
is preceeded by a tilde(~).
#include<iostream.h>
int count=0;
class alpha
{
public:
alpha()
{
count++;
cout<<No of objects created:<<count;
}
~ alpha()
{
cout<<no of objects destroyed:<<count;
}
};
void main()
{
cout<<enter main;
alpha A1,A2,A3,A4;
{
cout<<enter block1;
alpha A5;
}
{
cout<<enter block2;
alpha A6;
}
cout<<re-enter main;
}
Enter main
No of objects created:1
No of objects created:2
No of onjects created: 3
No of objects created:3
No of objects created:4
Enter block1:
No of objects created:5
No of objects destroyed:5
Enter block2:
No of objects created:5
No of objects destroyed:5
Re_enter main:
No of object destroyed:4
No of object destroyed:3
No of object destroyed:2
No of object destroyed:1
Here in the above program as the objects are created and destroyed, they
increase and decrease the count
First, 4 objects are created.
Then, entering block1, A5 is created and on exit from the block A5 is
destroyed.
FRIEND FUNCTION:
The main concepts of oop are data hiding and
data encapsulation. That is we are declaring variables in private part of a
class. So these members are restricted from accessing by non member
functions of the class. If any of the non member functions tries ti access
the members of the class , then a error messege is displayed .so for a non
member functions to have access to the members of the class they
should be declared in the public area which violates the data hiding and
encapsulation.
So the best way to access a private data member by a
non member functions is to declare a friend function to have access to
these data members.
Friend function:
Syntax:
NOTE:
2. friend function can be declared either in the private part or in the
public part of a class.
2.The keyword friend should be specified only in the function
declaration and it should not be specified in the function definition.
Ex:
Friend function disp() is declared in the public part
class first
{
private:
int x;
public:
void get();
friend void disp();
};
the friend function disp() is declared in the private part of the class.
class second
{
private:
int x;
friend void disp();
public:
void getdata();
};
Example:
#include<iostream.h>
class sample
{
private:
int x;
public:
void get();
friend void disp(class sample);
};
void sample :: get()
{
cout<Enter the value for x;
cin>>x;
}
void disp(class sample abc)
{
cout<Entered numbers are<<abc.x;
cout<<end l;
}
void main()
{
sample obj;
obj.get();
cout<<Accessing the private data by non member function;
}
#include<iostream.h>
class first
//Friend class
{
friend class econd;
private:
int x;
public:
void get();
};
class second
{
public:
void disp( first temp);
};
inline void first ::getdata()
{
cout<<Enter a number;
cin>>x;
}
inline void second :: disp( class first temp)
{
cout<<Entered numbers are :<<temp.x;
cout<<endl;
}
void main()
{
first objx;
second objy;
objx.get();
objy.disp(objx);
}
Syntax for declaring friend function with more than one class:
class first
{
private:
-----------public:
friend return type fname (class first , class second);
};
class second
{
private:
-----------public:
friend return type fname (class first , class second);
};
UNIT II
OPERATOR OVERLOADING
vector operator+(vector);
vector operator-();
int operator==(vec+);
Consider the unary minus operator, this operator changes the sign
of an operand when applied to a basic data item.
Now let us overload this unary minus operator so that it can be
applied to objects in the same way as it can be applied to an int or float
variable.
This unary minus when applied to an object, it changes the sign of
each of the data items.
Example Program:
#include<iostream.h>
class space
{
int x;
int y;
int z;
public:
void getdata(int a, int b, int c);
void display(void);
void operator-();
};
void space::getdata(int a,int b,int c)
{
x=a;
y=b;
z=c;
}
void space::display(void)
{
cout<<x;
cout<<y;
cout<<z;
}
void space::operator-()
{
x=-x;
y=-y;
z=-z;
}
int main()
{
space s;
s.getdata(10,-20,30);
cout<<s:;
s.display();
-s;
cout<<S:;
s.display();
return ;
}
Output:
S:
10
-20
30
S:
-10
20
-30
#include<iostream.h>
class complex
{
float x;
float y;
public:
complex();
complex(float real,float imag)
{
x=real;
y=imag;
}
complex operator+(complex);
void display();
};
complex complex::operator+(complex c)
{
complex temp;
temp.x=x+c.x;
temp.y=y+c.y;
return(temp);
}
void complex::display(void)
{
cout<<x<<+i<<y;
}
int main()
{
complex c1,c2,c3;
c1=complex(2.5,3.5);
c2=complex(1.6,2.7);
c3=c1+c2;
cout<<C1=;c1.display();
cout<<C2=;c2.display();
cout<<C2=;c2.display();
return 0;
}
Here the operator function +() receives one complex argument
explicity. One more argument for adding comes from the object that
invokes the operator function.
Thus the binary operator + is overloaded to add two complex numbers.
INHERITANCE
SYNTAX:
The general syntax for a derived class definition is:
EXAMPLE:
//Private derivation
Class ABC:private XYZ
{
Members of ABC;
};
//Public derivation
Class ABC:public XYZ
{
Members of ABC;
};
//private derivation by default
Class ABC:XYZ
{
Members of ABC;
}
In both the cases, the private part is not inherited. So while using
inheritance always declare the members in protected part and member
functions in public part. The visibility_mode, use always public.
TYPES OF INHERITANCE:
There are 5 types.
1. Single Inheritance.
2. Multilevel Inheritance.
3. Multiple Inheritance.
4. Hybrid Inheritance.
5. Heirarchial Inheritance.
SINGLE INHERITANCE:
A derived class with only one base class is called Single
Inheritance.
Single Inheritance
//A program to read the derived class data members such as name, roll
no, height and weight from the keyboard and display the contents on the
screen using Single Inheritance.
#include<stdio.h>
#include<conio.h>
Class stud
{
protected:
char name[10];
int roll_no;
public:
void getdata();
void display();
};
Class stud1:public stud
{
Protected:
Float height,weight;
Public:
Void getdata();
Void display();
};
Void stud::getdata()
{
Cout<<Enter a name:;
Cin>>name;
MULTILEVEL INHERITANCE:
The mechanism of deriving a class from another derived class is
called Multilevel Inheritance.
Baseclass
class for class C. Such types of derived classes are called virtual base or
indirect base.
Here class A is the direct base. Class B is the indirect base or
virtual base or Intermediate base. ABCInheritance Path.
Void putmarks
{
Student::putrno();
Cout<<marks 1:<<m1;
Cout<<marks 2:<<m2;
Cout<<marks 3:<<m3;
}
};
Class result:public test
{
Protected:
Int total;
Float avg;
Public:
Void display()
{
Total=m1+m2+m3;
Avg=total/3;
Test::putmarks;
Cout<<Total:<<total;
Cout<<Average:<<avg;
}
};
Void student::getrno()
{
Cout<<enter the roll number of student;
Cin>>roll_no;
}
Void student::putrno()
{
Cout<<Roll No:<<roll_no;
}
Void main()
{
Result r;
R.getmarks();
r.display();
}
Here the result is derived from the text which is derived from student.
Using the object of result, we can call the member functions of student
and test.
MUTIPLE INHERITANCE:
A derived class can inherit the attributes of two or more classes.
This is called Multiple Inheritance. Using multiple inheritance we can
combine the features of existing classes as a starting point for defining
new classes.
------(body of D)
};
HIERARCHICAL INHERITANCE:
When properties of one class is inherited by more than one class,
then the inheritance is called as Hierarchical Inheritance.
Here, the features of one class are shared by many classes below
that level. (i.e.,) The Base Class includes all the properties that are
common to the subclasses. A subclass can be inherited by inheriting the
properties of the base class. A subclass can be a base class for the lower
lavel classes and so on.
EXAMPLE:
BIRD
FLYING
BIRD
ROBIN
SWALLOW
NON FLYING
BIRD
PENGUIN
KIWI
HYBRID INHERITANCE:
POLYMORPHISM
poly many
morphism forms
Definition:
Polymorphism is the process of defining a number of objects of
different classes into a group and call the methods to carry out the
operation of the objects using different function calls.
Polymorphism is implemented by means of virtual functions.
VIRTUAL FUNCTIONS:
A virtual function is one that does not really exist but it appears
real in some parts of a program. Polymorphism is implemented by
means of virtual functions.
To make a member function virtual, the keyword virtual is used
in the member functions while it is declared in the class definition, but
not in the definition of member function. The keyword virtual should
precede the return type of the function name in the member function
declaration. On seeing the keyword virtual the compiler understands
that the function declared is a virtual function and not a conventional
function.
SYNTAX:
Class class-name
{
private:
----public:
virtual returntype function_name(args);
virtual returntype function_name(args);
virtual returntype function_name(args);
----};
TEMPLATES
FUNCTION TEMPLATE:
template does not specify the actual datatypes of the arguments that a
function accepts but it uses a generic or parameterized datatype.
Template<class template_name>
Template_name function_name
(template_name formal arguments)
{
return(template_name);
}
Template<class T>
T function_name(T formal arguments)
{
return(T);
The return type of the function is never considered for the actual
parameterized datatypes to be processes. The actual datatype of the
function matches with the formal arguments of the function declaration
whenever parameterized arguments are inferred in the function template.
EXAMPLE:
#include<iostream.h>
template<class T>T sum(T a[10],int n)
{
T temp=0;
For(int i=0;i<=n-1;i++)
Temp=temp+a[i];
Return(temp);
}
int sum(int a[10],int n);
float sum(float b[10],int n);
void main()
{
int n=3,sum1;
float sum2;
static int a[3]={1,2,3};
OUTPUT:
Sum of integers: 6
Sum of floating point numbers: 6.6
Here function template sum () has been declared as a generic
function for adding an array of values of the size upto n elements where
the number of elements are passed by the function call from the calling
portion of the program.
The sum () function template is called twice, once to find the sum
of integer array and again to find the sum of floating point numbers.
EXCEPTION HANDLING
Synchronous
Asynchronous
Three keywords here handle the exceptions: try, throw and catch.
TRY: It consists of a block of statements which may generate exceptions.
When any exception is found, it is thrown using a throw statement in
the try block.
Exception object
Try block
Detects and throws an
exception
Catch block
Catches and handles the
exception
SYNTAX:
----------try
{
----------throw exception;
----------}
catch(type arg)
{
----------}
-----------
If exception is not found at the try block, then the catch block is
skipped and the execution control after leaving the try-block moves to the
statement following the catch-block.
EXAMPLE:
#include<iostream.h>
int main()
{
int a,b;
cout<<Enter values of a and b;
cin>>a>>b;
int x=a-b;
try
{
if(x!=0)
{
cout<<Result(a/x)=<<a/x;
}
else
{
throw(x);
}
}
catch(int i)
{
cout<<Exception caught:X=<<x;
}
cout<<end;
return 0;
}
OUTPUT:
First run:
Enter values of a and b
20 15
Result(a/x)=4
End.
Here no exception.
Second run:
Enter values of a and b
10 10
Exception caught:X=0
End.
Throw exception
Invok
e function
Throw point
Function that causes
an exception
Try block
Invokes a function that
contains an exception
Catch block
Catches and handles
the exception
CLASS HIERARCHIES
Array
Sets
Lists
Stacks
Queues
Table
Maps
Dictionary
Tree
Graph
String datatypes
String length
Although formal strings can have an arbitrary (but finite) length, the
length of strings in real languages is often constrained to an artificial
maximum. In general, there are two types of string datatypes: fixed
length strings which have a fixed maximum length and which use the
same amount of memory whether this maximum is reached or not, and
variable length strings whose length is not arbitrarily fixed and which
use varying amounts of memory depending on their actual size. Most
strings in modern programming languages are variable length strings.
Despite the name, even variable length strings are limited in length;
although, generally, the limit depends only on the amount of memory
available..
Character encoding
Historically, string datatypes allocated one byte per character, and
although the exact character set varied by region, character encodings
were similar enough that programmers could generally get away with
Implementations
Some languages like C++ implement strings as templates that can be
used with any primitive type, but this is the exception, not the rule.
Representations
Representations of strings depend heavily on the choice of character
repertoire and the method of character encoding. Older string
implementations were designed to work with repertoire and encoding
defined by ASCII, or more recent extensions like the ISO 8859 series.
Modern implementations often use the extensive repertoire defined by
F R A N
NUL k
46 52 41 4E 4B 00
6B 66 66 77
Here is the equivalent (old style) Pascal string stored in a 10-byte buffer,
along with its ASCII representation:
lengt
h
05
R A N
46 52 41 4E 4B 6B 66 66 77
NIT III
OBJECT ORIENTATION
problems has been that each major methodology has had its own
graphical notation. This has all changed with the emergence of the UML
(Unified Modeling Language) as the standard notation. Any of the current
design methodologies, heavyweight or agile, use or can benefit from the
UML.
The UML originated in the mid-1990's from the efforts of James
Rumbaugh, Ivar Jacobson, and Grady Booch (The Three Amigos). There
is a standard specification of the UML coordinated by the Object
Management Group (www.omg.org). OMG is an industry sponsored
organization devoted to supporting vendor-neutral standards for the
object-oriented development community. The UML has become the de
facto standard object-oriented notation.
The UML is designed for discussing object-oriented design. Its
ability to show objects and object relationships is especially useful, and
will be used in examples throughout this book. The various features of
the UML will be introduced as needed.
REVIEW OF OBJECTS
objects:
EXAMPLE:
A car
Consider a santro car.
santro can be represented in computer program as an object.
Datapart of this object cars name, color, number of doors, price and so
forth.
Logic part of the object is a collection of programs (show mileage,
change mileage, stop, go).
EXAMPLE:
Employee class.
(i.e.) employees such as eno 1, eno 2, eno n are instances of the class
employee.
INHERITANCE
SYNTAX:
The general syntax for a derived class definition is:
EXAMPLE:
//Private derivation
Class ABC:private XYZ
{
Members of ABC;
};
//Public derivation
Class ABC:public XYZ
{
Members of ABC;
};
//private derivation by default
Class ABC:XYZ
{
Members of ABC;
}
OBJECT RELATIONSHIPS
Can fly
flownPilot
by
Planes
Cardinality:
It is the important issue of association. It specifies how many
instances of one class may relate to a single instance of an associated
class. It constrains the number of related objects and often is described
as being one or many.
EXAMPLE:
A client-account relationship.
One client can have one or more accounts and vice versa ( in case of joint
accounts). Here cardinality of the client account is many to many.
Print Server
Item
For printing
We have a print object that prints the consumer object. The print
producer provides the ability to print other objects.
DYNAMIC BINDING
5. Reusability
Software development process:
System development can be viewed as a process. (i.e.) The software
development is a process of change refinement, transformation or
addition to the existing product. Within a process, it is possible to
replace one subprocess with a new one, and the subprocess should have
the same interface to fit into the process. With this change, it is possible
to have a new process. (i.e.) Subprocesses changes the behaviour of the
parent process in a consistent way.
Each subprocess should have the following:
TRANSFORMATION 1 (ANALYSIS):
It translates the users needs into system requirements and
responsibilities. The way the users use the system provides the user
requirements.
TRANSFORMATION 2 (DESIGN):
Begins with a problem statement and ends with a detailed design
that can be transformed into an operational system. Most of the software
development activities such as definition of building a software, software
development and its testing takes place during this transformation.
TRANSFORMATION 3 (IMPLEMENTATION):
Software Process
Transformation 1
Users of the
system
Transformation 2 Transformation 3
Problem
ststement
analysis
Building
high quality software:
What
Four quality measures are:
How
1. Correspondence
2. Validation
3. Correctness
Do it
4. Verification
Test
Correspondence measures how well the delivered system
matches the needs of the operational environment as described
Use
in the original requirements statement.
1. Object-Oriented Analysis
2. Object-Oriented Design
3. Object-Oriented Implementation
The use-case model is employed throughout most activities of
software development.
OOSD includes these activities:
1. Object-Oriented analysis Use case driven
2. O-O design
3. Prototyping
4. Component-based development
5. Incremental testing
Object Oriented design:
In this phase, we have to first build the object model based on
objects and their relationships, then iterate and refine the model:
Prototyping:
Categories of Prototypes are:
1. Horizontal prototype
2. Vertical prototype
3. Analysis prototype
4. Domain prototype
Implementation:
Component based development (CBD):
Incremental testing:
OVERVIEW OF METHODOLOGY
A software development methodology is a series of processes,
that if followed can lead to the development of an application.
Systems development refers to all activities that go into
producing an information systems solution.
UNIT IV
Jim has a B.S. in physics from MIT, an M.S. in astronomy from Caltech,
and a Ph.D. in computer science from MIT.
He has written a number of books about UML and RUP together with Ivar
Jacobson and Grady Booch.
BOOCH METHODOLOGY
The notation aspect of the Booch method has now been superseded by
the Unified Modeling Language (UML), which features graphical elements
from the Booch method along with elements from the object-modeling
technique (OMT) and object-oriented software engineering (OOSE).
Methods
UML is not a method by itself; however, it was designed to be compatible
with the leading object-oriented software development methods of its
time (for example OMT, Booch, Objectory). Since UML has evolved, some
of these methods have been recast to take advantage of the new notation
(for example OMT), and new methods have been created based on UML.
The best known is Rational Unified Process (RUP). There are many other
UML-based methods like Abstraction Method, Dynamic Systems
Development Method, and others, designed to provide more specific
solutions, or achieve different objectives.
Modeling
It is very important to distinguish between the UML model and the set of
diagrams of a system. A diagram is a partial graphical representation of a
system's model. The model also contains a "semantic backplane"
documentation such as written use cases that drive the model elements
and diagrams.
Diagrams
CLASS DIAGRAM
In the Unified Modeling Language (UML), a class diagram is a type of
static structure diagram that describes the structure of a system by
showing the system's classes, their attributes, and the relationships
between the classes.
RELATIONSHIPS
A relationship is a general term covering the specific types of logical
connections found on class and object diagrams. UML shows the
following relationships:
Instance-Level Relationships
Link
A Link is the basic relationship among objects. It is represented as a line
connecting two or more object boxes. It can be shown on an object
diagram or class diagram. A link is an instance of an association.
Association
Aggregation
Composition
Composition is a stronger variant of the "has a" or association
relationship; composition is more specific than aggregation.
Generalisation
Generalisation-Specialization relationship
A is a type of B
E.g. "an oak is a type of tree", "a automobile is a type of vehicle"
Generalisations can only be shown on class diagrams and on Use case
diagrams.
Realisation
In UML modeling, a realisation relationship is a relationship between two
model elements, in which one model element (the client) realises the
behavior that the other model element (the supplier) specifies. A
realisation is displayed in the diagram editor as a dashed line with an
unfilled arrowhead towards the supplier.
GENERAL RELATIONSHIP
Dependency (UML)
A dependency exists between two defined elements if a change to the
definition of one would result in a change to the other. This is indicated
by a dashed arrow pointing from the dependent to the independent
element. Several named varieties exist. A dependency can be between
instances, classes, or both.
Multiplicity
The association relationship indicates that (at least) one of the two
related classes makes reference to the other. In contrast with the
generalization relationship, this is most easily understood through the
phrase 'A has a B' {a mother cat has kittens, kittens have a mother cat}.
0..1
1
0..* or
*
1..*
AGGREGATION
Aggregation differs from ordinary composition in that it does not imply
ownership. In composition, when the owning object is destroyed, so are
the contained objects. In aggregation, this is not necessarily true. For
example, a university owns various departments (e.g., chemistry), and
each department has a number of professors. If the university closes, the
departments will no longer exist, but the professors in those departments
will continue to exist. Therefore, a University can be seen as a
composition of departments, whereas departments have an aggregation
of professors. In addition, a Professor could work in more than one
department, but a department could not be part of more than one
university.
class Professor;
class Department
{
...
private:
// Aggregation
Professor* members[5];
...
};
class University
{
...
private:
// Composition
Department faculty[20];
...
};
In aggregation, the object may only contain a reference or pointer to the
object (and not have lifetime responsibility for it):
The above code would transform into the following UML Class diagram:
UNIT V
OO
Design
axioms
Class
visibility
refining
OO DESIGN AXIOMS
Object oriented design is part of OO methodology and it forces
programmers to think in terms of objects, rather than procedures, when
they plan their code. An object contains encapsulated data and
procedures grouped together to represent an entity. The 'object interface',
how the object can be interacted, is also defined. An object oriented
program is described by the interaction of these objects. Object-oriented
design is the discipline of defining the objects and their interactions to
solve a problem that was identified and documented during objectoriented analysis.
Designing concepts
Defining objects, creating class diagram from conceptual diagram:
Usually map entity to class.
Identifying attributes.
Use design patterns (if applicable): A design pattern is not a finished
design, it is a description of a solution to a common problem. The main
advantage of using a design pattern is that it can be reused in multiple
applications. It can also be thought of as a template for how to solve a
problem that can be used in many different situations and/or
applications. Object-oriented design patterns typically show relationships
and interactions between classes or objects, without specifying the final
application classes or objects that are involved.
Define application framework (if applicable): Application framework is a
term usually used to refer to a set of libraries or classes that are used to
implement the standard structure of an application for a specific
operating system. By bundling a large amount of reusable code into a
framework, much time is saved for the developer, since he/she is saved
the task of rewriting large amounts of standard code for each new
application that is developed.
Identify persisted objects/data (if applicable): Identify objects that have to
be persisted. If relational database is used design the object relation
mapping.
Identify, define remote objects (if applicable)
Programming concepts
Aspect oriented programming: One view of aspect-oriented programming
(AOP) is that every major feature of the program, core concern (business
logic), or cross-cutting concern (additional features), is an aspect, and by
weaving them together (also called composition), you finally produce a
whole out of the separate aspects.
Dependency injection: The basic idea is that if an object depends upon
having an instance of some other object then the needed object is
"injected" into the dependent object. For example, being passed a
database connection as an argument to the constructor instead of
creating one internally
METHODS
In software engineering and project management, a methodology is a
codified set of practices (sometimes accompanied by training materials,
formal educational programs, worksheets, and diagramming tools) that
may be repeatably carried out to produce software.
(rather than directly accessing the balance data fields), then later
revisions of the same code can implement a more complex mechanism
balance retrieval (say, a database fetch) without the dependent code
needing to be changed. An accessor method that changes the state of an
object is called an update method, a modifier method, or a mutator
method. Objects that provide such methods are considered mutable
objects.
Some languages have a special syntax for Constructors, i.e. methods that
are called automatically upon the creation of an instance of a class. In
Java, C++, C#, ActionScript, and PHP they are distinguished by having
the same name as the class of the object they're associated with (PHP 5
also allows __construct as a constructor); in Visual Basic the constructor
is called New, and in Object Pascal constructors can have user-defined
names (but are mostly called Create). Under Objective-C the constructor
method is split between two methods, alloc and init, with the alloc
method setting aside memory for an instance of the class and the init
method handling the bulk of initializing the instance; a call to the new
method invokes both the alloc and the init method for the class instance.
Isolation levels
Whereas a C programmer might push a value onto a stack data-structure
by calling:
stackPush(&myStack, value);
a C++ programmer would write:
myStack.push(value);
The difference is the required level of isolation. In C, the stackPush
procedure could be in the same source file as the rest of the program and
if it was, any other pieces of the program in that source file could see and
modify all of the low level details of how the stack was implemented,
completely bypassing the intended interface. In C++, regardless of where
the class is placed, only the functions which are part of myStack will be
able to get access to those low-level details without going through the
formal interface functions. Languages such as C can provide comparable
levels of protection by using different source files and not providing
external linkage to the private parts of the stack implementation but this
is less neat and systematic than the more cohesive and enforced isolation
of the C++ approach.
ACCESS LAYER
A Data access layer is a layer of a computer program which provides
simplified access to data stored in persistent storage of some kind, such
as an entity-relational database.
For example, the DAL might return a reference to an object (in terms of
object-oriented programming) complete with its attributes instead of a
row of fields from a database table. This allows the client (or using)
modules to be created with a higher level of abstraction. This kind of
model could be implemented by creating a class of data access methods
which directly reference a corresponding set of database stored
procedures. Another implementation could potentially retrieve or write
records on to a file system. The DAL, hides from the external world, this
complexity of the underlying data store.
Consider that you have to interact from a specific table in the database
(like insert, delete, update) then you just create a class and a few stored
procedures in the database, where you call those Stored Procedures from
a method inside the class. and class in return on the coding side will
return an object containing the requested values.
OODBMS
In an object oriented database, information is represented in the form of
objects as used in Object-Oriented Programming. When database
Some object-oriented databases are designed to work well with objectoriented programming languages such as Python, Java, C#, Visual
Basic .NET, C++ and Smalltalk. Others have their own programming
languages. ODBMSs use exactly the same model as object-oriented
programming languages.
Technical features
Most object databases also offer some kind of query language, allowing
objects to be found by a more declarative programming approach. It is in
the area of object query languages, and the integration of the query and
navigational interfaces, that the biggest differences between products are
found. An attempt at standardization was made by the ODMG with the
Object Query Language OQL.
Access to data can be faster because joins are often not needed (as in a
tabular implementation of a relational database). This is because an
object can be retrieved directly without a search, by following pointers. (It
could, however, be argued that "joining" is a higher-level abstraction of
pointer following.)
Another area of variation between products is in the way that the schema
of a database is defined. A general characteristic, however, is that the
programming language and the database schema use the same type
definitions.
Standards
The Object Data Management Group (ODMG) was a consortium of object
database and object-relational mapping vendors, members of the
academic community, and interested parties. Its goal was to create a set
of specifications that would allow for portable applications that store
objects in database management systems. It published several versions
of its specification. The last release was ODMG 3.0. By 2001, most of the
major object database and object-relational mapping vendors claimed
conformance to the ODMG Java Language Binding. Compliance to the
Many object database ideas were also absorbed into SQL:1999 and have
been implemented in varying degrees in object-relational database
products.
TABLE
In relational databases, SQL databases, and flat file databases, a table is
a set of data elements (values) that is organized using a model of
horizontal rows and vertical columns. The columns are identified by
name, and the rows are identified by the values appearing in a particular
column subset which has been identified as a candidate key. Table is
another term for relations; although there is the difference in that a table
is usually a multi-set (bag) of rows whereas a relation is a set and does
not allow duplicates. A table has a specified number of columns but can
have any number of rows. Besides the actual data rows, tables generally
have associated with them some meta-information, such as constraints
on the table or on the values within particular columns.
The data in a table does not have to be physically stored in the database.
Views are also relational tables, but their data is calculated at query
time. Another example are nicknames, which represent a pointer to a
table in another database.
One of the most widely used paradigms for QA management is the PDCA
(Plan-Do-Check-Act) approach, also known as the Shewhart cycle.
Both anthropology and sociology have made detailed studies in this area.
Many cultures feature patrilineal succession, also known as gavelkind,
where only male children can inherit. Some cultures also employ
matrilineal succession only passing property along the female line. Other
practices include primogeniture, under which all property goes to the
eldest child, or often the eldest son, or ultimogeniture, in which
everything is left to the youngest child. Some ancient societies and most
modern states employ partible inheritance, under which every child
inherits (usually equally). Historically, there were also mixed systems:
In eastern Swedish culture, from the 13th century until the 19th
century, sons inherited twice as much as daughters. This rule was
introduced by the Regent Birger Jarl, and it was regarded as an
improvement in its era, since daughters were previously usually left
without.
Among ancient Israelites, the eldest son received twice as much as the
other sons.
Among Galician people it was typical that all children (both men and
women) had a part of the inheritance, but one son (the one who inherited
the house) inherited one-third of all the inheritance. This son was called
the mellorado. In some villages the mellorado even received two-thirds of
all the inheritance. This two-thirds would be all the family's lands, while
other children received their part in money.
According to Islamic inheritance jurisprudence, sons inherit twice as
much as daughters when no will is left. The complete laws governing
inheritance in Islam are complicated and take into account many kinship
relations (so wills are usually recommended), but in principle males
inherit twice as females. There is one interesting exception: The
Indonesian Minangkabau people from West part of Sumatra island
despite being strong Muslims employ only complete matrilineal
succession with property and land passing down from mother to
daughter. They find no contradiction between their culture and faith.
Many states have inheritance taxes, under which a portion of any estate
goes to the government, though the government technically is not an
heir.
In more archaic days, the possession of inherited land has been much
more like a family trust than a property of an individual. Even in recent
years, the sale of the whole of or a significant portion of a farm in many
European countries required consent from certain heirs, and/or heirs
had the intervening right to obtain the land in question with same sales
conditions as in the sales agreement in question.
In modern legal use, the terms inheritance and heir refer only to
succession of property from a decedent who has died intestate (that is,
without a will). It is a common mistake to refer to the recipients of
property through a will as heirs when they are properly called devisees or
legatees.
TEST PLAN
A test plan is a systematic approach to testing a system such as a
machine or software. The plan typically contains a detailed
understanding of what the eventual workflow will be.
* Scope of testing
* Schedule
* Test Deliverables
* Release Criteria
* Risks and Contingencies
For example: "Master plan for 3A USB Host Mass Storage Driver
TP_3A1.0"
Introduction
State the purpose of the Plan, possibly identifying the level of the plan
(master etc.). This is essentially the executive summary part of the plan.
Identify the objective of the plan or scope of the plan in relation to the
Software Project plan that it relates to. Other items may include,
resource and budget constraints, scope of the testing effort, how testing
relates to other evaluation activities (Analysis & Reviews), and possible
the process to be used for change control and communication and
coordination of key activities.
This section can be oriented to the level of the test plan. For higher levels
it may be by application or functional area, for lower levels it may be by
program, unit, module or build.
Safety.
Multiple interfaces.
Impacts on Client.
Government regulations and rules.
Another key area of risk is a misunderstanding of the original
requirements. This can occur at the management, user and developer
levels. Be aware of vague or unclear requirements and requirements that
cannot be tested.
The past history of defects (bugs) discovered during Unit testing will help
identify potential areas within the software that are risky. If the unit
testing discovered a large number of defects or a tendency towards
defects in a particular area of the software, this is an indication of
potential future problems. It is the nature of defects to cluster and clump
together. If it was defect ridden earlier, it will most likely continue to be
defect prone.
One good approach to define where the risks are is to have several
brainstorming sessions.
Features to be tested
This is a listing of what is to be tested from the user's viewpoint of what
the system does. This is not a technical description of the software, but a
USERS view of the functions.
Set the level of risk for each feature. Use a simple rating scale such as
High, Medium and Low(H, M, L). These types of levels are understandable
to a User. You should be prepared to discuss why a particular level was
chosen.
Sections 4 and 6 are very similar, and the only true difference is the
point of view. Section 4 is a technical type description including version
Identify why the feature is not to be tested, there can be any number of
reasons.
Approach (strategy)
This is your overall test strategy for this test plan; it should be
appropriate to the level of the plan (master, acceptance, etc.) and should
be in agreement with all higher and lower levels of plans. Overall rules
and processes should be identified.
Test deliverables
List documents, reports, charts, that will be presented to stakeholders on
a regular basis during testing and when testing has been completed.
the users and testers to avoid incomplete functions and prevent waste of
resources chasing non-defects.
When a third party is developing the software, this section may contain
descriptions of those test tasks belonging to both the internal groups and
the external groups.
Environmental needs
Are there any special requirements for this test plan, such as:
The Test Items and Responsibilities sections affect this section. What is
to be tested and who is responsible for the testing and training.
Responsibilities
Who is in charge?
This issue includes all areas of the plan. Here are some examples:
Setting risks.
Selecting features to be tested and not tested.
Setting overall strategy for this level of plan.
Ensuring all required elements are in place for testing.
Providing for resolution of scheduling conflicts, especially, if testing is
done on the production system.
Who provides the required training?
Who makes the critical go/no go decisions for items not covered in the
test plans?
Approvals
Who can approve the process as complete and allow the project to
proceed to the next level (depending on the level of the plan)?
At the master test plan level, this may be all involved parties.
When determining the approval process, keep in mind who the audience
is:
The audience for a unit test level plan is different from that of an
integration, system or master level plan.
The levels and type of knowledge at the various levels will be different as
well.
Programmers are very technical but may not have a clear understanding
of the overall business process driving the project.
Users may have varying levels of business acumen and very little
technical skills.
Always be wary of users who claim high levels of technical skills and
programmers that claim to fully understand the business process. These
types of individuals can cause more harm than good if they do not have
the skills they believe they possess.
A test plan documents the strategy that will be used to verify and ensure
that a hardware product or system meets its design specifications and
other requirements. A test plan is usually prepared by or with significant
input from Test Engineers.
A complex system may have a high level test plan to address the overall
requirements and supporting test plans to address the design details of
subsystems and components.
Test coverage in the test plan states what requirements will be verified
during what stages of the product life. Test Coverage is derived from
design specifications and other requirements, such as safety standards
or regulatory codes, where each requirement or specification of the
design ideally will have one or more corresponding means of verification.
Test coverage for different product life stages may overlap, but will not
necessarily be exactly the same for all stages. For example, some
requirements may be verified during Design Verification test, but not
repeated during Acceptance test. Test coverage also feeds back into the
design process, since the product may have to be designed to allow test
access (see Design For Test).
Test methods in the test plan state how test coverage will be
implemented. Test methods may be determined by standards, regulatory
agencies, or contractual agreement, or may have to be created new. Test
methods also specify test equipment to be used in the performance of the
tests and establish pass/fail criteria. Test methods used to verify
hardware design requirements can range from very simple steps, such as
USABILITY TESTING
Usability testing is a means for measuring how well people can use some
human-made object (such as a web page, a computer interface, a
document, or a device) for its intended purpose, i.e. usability testing
measures the usability of the object. Usability testing focuses on a
particular object or a small set of objects, whereas general humancomputer interaction studies attempt to formulate universal principles.
feedback, then developers should improve the design and test it again.
During usability testing, the aim is to observe people using the product
in as realistic a situation as possible, to discover errors and areas of
improvement. Designers commonly focus excessively on creating designs
that look "cool", compromising usability and functionality. This is often
caused by pressure from the people in charge, forcing designers to
develop systems based on management expectations instead of people's
needs. A designer's primary function should be more than appearance,
including making things work with people.
Rather than showing users a rough draft and asking, "Do you
understand this?", usability testing involves watching people trying to
use something for its intended purpose. For example, when testing
instructions for assembling a toy, the test subjects should be given the
instructions and a box of parts. Instruction phrasing, illustration quality,
and the toy's design all affect the assembly process.
Time on Task -- How long does it take people to complete basic tasks?
(For example, find something to buy, create a new account, and order the
item.)
Accuracy -- How many mistakes did people make? (And were they fatal or
recoverable with the right information?)
Recall -- How much does the person remember afterwards or after
periods of non-use?
Emotional Response -- How does the person feel about the tasks
completed? (Confident? Stressed? Would the user recommend this
system to a friend?)
In the early 1990s, Jakob Nielsen, at that time a researcher at Sun
Microsystems, popularized the concept of using numerous small
usability tests -- typically with only five test subjects each -- at various
stages of the development process. His argument is that, once it is found
that two or three people are totally confused by the home page, little is
gained by watching more people suffer through the same flawed design.
"Elaborate usability tests are a waste of resources. The best results come
from testing no more than 5 users and running as many small tests as
you can afford." 2. Nielsen subsequently published his research and
coined the term heuristic evaluation.
U = 1 (1 p)n
In later research Nielsen's claim has eagerly been questioned with both
empirical evidence 3 and more advanced mathematical models (Caulton,
D.A., Relaxing the homogeneity assumption in usability testing.
Behaviour & Information Technology, 2001. 20(1): p. 1-7.). Two of the key
challeges to this assertion are: (1) since usability is related to the specific
set of users, such a small sample size is unlikely to be representative of
the total population so the data from such a small sample is more likely
to reflect the sample group than the population they may represent and
(2) many usability problems encountered in testing are likely to prevent
exposure of other usability problems, making it impossible to predict the
percentage of problems that can be uncovered without knowing the
relationship between existing problems. Most researchers today agree
that, although 5 users can generate a significant amount of data at any
given point in the development cycle, in many applications a sample size
larger than five is required to detect a satisfying amount of usability
problems.
USER SATISFACTION
Computer user satisfaction (and closely related concepts such as System
Satisfaction, User Satisfaction, Computer System Satisfaction, End User
Computing Satisfaction) deals with user attitudes to computer systems in
the context of their environments. In a broader sense, the definition can
be extended to user satisfaction with any computer-based electronic
appliance. The term Computer User Satisfaction is abbreviated to user
satisfaction in this article. In general, the development of techniques for
defining and measuring user satisfaction have been ad hoc and open to
question. However, according to key scholars such as DeLone and
McLean (2002), user satisfaction is a key measure of computer system
success, if not in fact synonymous with it. Interest in the concept thus
continues. Scholars distinguish between user satisfaction and usability
as part of Human-Computer Interaction.
TESTING
Software testing is the process used to measure the quality of developed
computer software. Usually, quality is constrained to such topics as
correctness, completeness, security, but can also include more technical
requirements as described under the ISO standard ISO 9126, such as
Today, software has grown in complexity and size. The software product
developed by a developer is according to the System Requirement
Specification. Every software product has a target audience. For example,
a video game software has its audience completely different from banking
software. Therefore, when an organization invests large sums in making a
software product, it must ensure that the software product must be
acceptable to the end users or its target audience. This is where Software
Testing comes into play. Software testing is not merely finding defects or
bugs in the software, it is the completely dedicated discipline of
evaluating the quality of the software.