OOT (Unit I According To Rgtu Syllabus)
OOT (Unit I According To Rgtu Syllabus)
OOT (Unit I According To Rgtu Syllabus)
opasdfghjklzxcvbnmqwertyuiopasdfgh
jklzxcvbnmqwertyuiopasdfghjklzxcvb
nmqwertyuiopasdfghjklzxcvbnmqwer
tyuiopasdfghjklzxcvbnmqwertyuiopas
dfghjklzxcvbnmqwertyuiopasdfghjklzx
cvbnmqwertyuiopasdfghjklzxcvbnmq
wertyuiopasdfghjklzxcvbnmqwertyuio
Venkteshwar Institute Of Tech.Indore
OOT notes(CS-403)
pasdfghjklzxcvbnmqwertyuiopasdfghj
klzxcvbnmqwertyuiopasdfghjklzxcvbn
BY:
Er.NIVEDITA SHIRKE
(CS/IT dpt.)
mqwertyuiopasdfghjklzxcvbnmqwerty
uiopasdfghjklzxcvbnmqwertyuiopasdf
ghjklzxcvbnmqwertyuiopasdfghjklzxc
vbnmqwertyuiopasdfghjklzxcvbnmrty
uiopasdfghjklzxcvbnmqwertyuiopasdf
ghjklzxcvbnmqwertyuiopasdfghjklzxc
Venkteshwar Institute Of Tech.Indore
History
The terms "objects" and "oriented" in something like the modern sense of object-oriented
programming seem to make their first appearance at MIT in the late 1950s and early 1960s.
Object-oriented programming developed as the dominant programming methodology in the
early and mid 1990s when programming languages supporting the techniques became widely
available. More recently, a number of languages have emerged that are primarily object-
oriented yet compatible with procedural methodology, such as Python and Ruby. Probably the
most commercially important recent object-oriented languages are Visual Basic.NET (VB.NET)
and C#, both designed for Microsoft's .NET platform, and Java, developed by Sun Microsystems.
Programming Approaches
1. Modular Programming Approach:- In this approach we have some code that are
implemented thru short of modules. We basically empasize on that modules and that
modules are collectively form a program in a sequence.Like-JAVA Simula.
2. Top-Bottom Programming Approach :- It includes POP programming
3. Bottom-Up Programming Approach :- It includes OOP programming.
4. Structured Programming Approach :- Structured programming (sometimes known as
modular programming) is a subset of procedural programming that enforces a logical
structure on the program being written to make it more efficient and easier to
understand and modify. It was unale to make reusable code, also it was difficult to
maintain, so was not much popular.
2. The Different part of the program connects with each other by parameter passing & using
operating system.
9. More data or functions can not be added with program if necessary. For this purpose full
program need to be change.
10. To add new data in program user should be ensure that function allows it.
3. Data & functions of each individual object act like a single unit.
7. Data hiding possible in OOP which prevent illegal access of function from outside of it.
This is one of the best advantages of OOP also.
9. More data or functions can be added with program if necessary. For this purpose full
program need not to be change.
10. Message passing ensure the permission of accessing member of an object from other
object.
We can summarize:
Merits of OOP:
1. It is possible to have multiple instances of an object to co-exist without any interference.
2. Each object leads itself to achieve greater modularity.
3. Object shares their responsibilities to achieve the consistency.
4. Data centered design approach enables to capture more implementation details.
5. We can extend the code through reusability.
Demerits of OOP:
1. Type of the software to be developed.
2. Preferences of the software developer.
3. Resources and environment available.
Applications of OOP:
1. Office automation system
2. Real time systems
3. Hypermedia.
4. Computer aided designing.
5. Neural networks
6. Simulation and modelling.
Features of OOPs
1. Object
2. Classes
3. Data abstraction and encapsulation
4. Inheritance
5. Polymorphism
6. Dynamic Binding
7. Message passing
Properties:
OBJECTS
Note:If you got the Question about Object -like describe objects or
explain objects or give details about object then you have to cover the
following points,write same as according to the following points:
1. Defination of object(1 bolck diagram)
2. Representation of objects
3. Memory allocation of objects
4. Syntax
5. Components of object
6. Example(program of object)
Player Object:
data:
health
strength
agility
type of weapon
type of armor
actions:
move
attack monster
get treasure
END;
There is a very important distinction between an object and an instance of an object. An object
is actually a definition, or a template for instances of that object. An instance of an object is an
actual thing that can be manipulated. For instance, we could define a Person object, which may
include such member data as hair color, eye color, height, weight, etc. An instance of this object
could be "Dave" and Dave has values for hair color, eye color, etc. This allows for multiple
instances of an object to be created. Let's go back to the medieval video game example and
define the monster object.
Monster Object:
data:
health
skin thickness
claws
tail spikes
actions:
move
attack player with claws
attack player with tail
END;
health = 16
strength = 12
agility = 14
type of weapon = "mace"
type of armor = "leather"
END;
4. Syntax:
Private:
Data members;
Member function;
Public:
Member functions;
Protected:
Data members;
}; class_name obj1,obj2,objn;
5.Components:
1. Data members
2. Member functions
3. Static data members
4. Static member function
5. Const member function
Example:
Let
Box b1,b2;
class Box
public :
void get_data()
cin>>l>>h>>w;
void display()
};
main ()
Box b1,b2;
In above example b1 and b2 are the two objects of the class Box. Here the object b1 and b2
both have their own copy of variables l, h, w ,and created on the same line. The Object can
be created on separate line
Box b1;
Box b2;
There is another place where objects can be created i.e. at the time of defining a class by
placing objects name after the ending brace but before the semicolon of class.
class Box
members
}b1,b2;
Classes
5. Varieties of class
Representation:
CLASS : IT IT
DATA MEMBERS:
Getinfo()
Name;
Age:
……..
MEMBER FUNCTIONS:
Getinfo();
Showinfo()
Showinfo();
………..
Components of class:
Data encapsulation
Data abstraction
Inheritance
Polymorphism
Varieties of classes:
6. Base class
7. Derived class
Attributes or Variables
Methods or functions
2. NEED: Functions are useful when we need to divide large and complex programs into
small one.
3. Program:
#include <iostream>
int r;
r=a+b;
return (r);
int main ()
int z;
z = addition (5,3);
return 0;
Inline Function:
An inline function is one for which the compiler copies the code from the function definition
directly into the code of the calling function rather than creating a separate set of instructions
in memory. Instead of transferring control to and from the function code segment, a modified
copy of the function body may be substituted directly for the function call. In this way, the
performance overhead of a function call is avoided.A function is declared inline by using the
inline function specifier or by defining a member function within a class or structure definition.
The inline specifier is only a suggestion to the compiler that an inline expansion can be
performed; the compiler is free to ignore the suggestion.
In C++, both member and nonmember functions can be inlined. Member functions
that are implemented inside the body of a class declaration are implicitly declared inline.
Constructors, copy constructors, assignment operators, and destructors that are created by the
compiler are also implicitly declared inline. An inline function that the compiler does not inline
is treated similarly to an ordinary function: only a single copy of the function exists, regardless
of the number of translation units in which it is defined.
The keyword inline specified in the above example, designates the function as inline function.
For example, if a programmer wishes to have a function named exforsys(execution for system)
with return value as integer and with no arguments as inline it is written as follows:
#include <iostream.h>
int exforsys(int);
void main( )
int x;
cin>>x;
return 5*x1;
One of the important advantage of the inline function in a program is that they help us to save
memory space.This is useful in case when a function is likely to be called many times.The
overheads involved in calling a function are:
Returning values
Saving register
Pushing arguments into stack
So, by calling again and again it takes a lot of time in executing a series of instruction.So,
the solution to this problem is:
One solution to this problem is to use macro definations, but these are popular in C.
Macros definition: Macros are most frequently used to define names for constants that
occur repeatedly in a program. The more preferred way of defining these constants is by using
the keyword const. Since the current focus is not on which is the best way to define constants,
let us leave it alone. The #define directive is quite powerful and hence allows the macro name
to have arguments and thus behave like a function. Such forms of macros are referred to as
function-like macros. Each time the macro name is encountered with arguments, the
arguments used in its definition are replaced by the actual arguments found.
For example:
Collapse
#include "iostream.h"
cout << "Maximum of 10 and 20 is " << MAX(10, 20) << endl;
return 0;
Collapse
Output:
Disadvantage: They are not really functions and that’s why the usual checking doesn’t
occur during compilation of a program.
2) It also save overhead of variables push/pop on the stack, while function calling.
5) After in-lining compiler can also apply intraprocedural optmization if specified. This is the
most important one, in this way compiler can now focus on dead code elimination, can give
more stress on branch prediction, induction variable elimination etc..
Disadvantages :-
1) May increase function size so that it may not fit on the cache, causing lots of cahce miss.
2) After in-lining function if variables number which are going to use register increases than
they may create overhead on register variable resource utilization.
3) It may cause compilation overhead as if some body changes code inside inline function than
all calling location will also be compiled.
4) If used in header file, it will make your header file size large and may also make it
unreadable.
5) If somebody used too many inline function resultant in a larger code size than it may cause
thrashing in memory. More and more number of page fault bringing down your program
performance.
6) Its not useful for embeded system where large binary size is not preferred at all due to
memory size constraints.
Friend function:
The friend function is written as any other normal function, except the function declaration of
these functions is preceded with the keyword friend. The friend function must have the class to
which it is declared as friend passed to it in argument.
1. The keyword friend is placed only in the function declaration of the friend function and
not in the function definition.
3. When a class is declared as a friend, the friend class has access to the private data of the
class that made this a friend.
4. A friend function, even though it is not a member function, would have the rights to
access the private members of the class.
6. The function can be invoked without the use of an object. The friend function has its
argument as objects, seen in example below.
#include
class exforsys
private:
int a,b;
public:
void test()
a=100;
b=200;
//Friend Function Declaration with keyword friend and with the object of class exforsys to
which it is friend passed to it
};
return int(e1.a+e2.b)-5;
main()
exforsys e;
e.test();
1. Customer object
2. Account object
Then the “customer object” may send a message to the “account object” to know the bank
balance as an request.Customer obj.contains data and code to manipulate the data.Customer
obj.interact with account object without knowing the details of each other’s data and code.
Message passing involves specifying the name of the object,the name of the function(message)
and the information to be sent.
Example:
Employee.salary(name);
Here:
1. Employee ia an object
2. Salary is a message
3. Name is an information
Types of objects:
1. External or global objects:
Existence- Throughout the lifetime of the whole program.
Visibility-Globally available to all modules.
3. Static objects
Existence- Throughout the whole program.
Visibility-Local scope in which objects are created.
4. Dynamic objects:
Existence-Lifetime may be controlled within a particular scope.
Visibility-Within a particular scope.
State of Objects:
Object Oriented technology Page 20
Venkteshwar Institute Of Tech.Indore
Meta Class
In object-oriented programming, a metaclass is a class whose instances are classes. Just as an
ordinary class defines the behavior of certain objects, a metaclass defines the behavior of
certain classes and their instances. Not all object-oriented programming languages support
metaclasses. Among those that do, the extent to which metaclasses can override any given
aspect of class behavior varies. Each language has its own metaobject protocol, a set of rules
that govern how objects, classes, and metaclasses interact.
- "a default constructor pointer" of the described class (only if it is a dynamic one).
- all declared metaclasses list access for the binary and its potential modules,
- a function that searches for a metaclass from a given class tag identification,
The diagram shows the symbol for a class in OMT notation. The attributes and operations
correspond to C++ data and function members.
Here we are illustrating single inheritance. The land and water vehicle classes are subclasses of
vehicle.
notation (e.g. between the CONSOLE and the PUMP), which is similar to a relationship in entity-
relationship notations.
The dynamic model consists of a state transition diagram (STD) for each of the classes in the
object model.
The STD notation is that defined by Harel (1987), which allows for decomposable states. This is
richer and more powerful than that commonly used in Yourdon.
The functional model uses a hierarchy of data flow diagrams (DFDs) in a similar fashion to the
Yourdon method. However, the DFDs are not very well integrated with the object and dynamic
models and it is difficult to imagine many projects making extensive use of the functional
model.
Some aspects of the functional model are, however, quite useful. For example, the context
diagram is vital for defining the scope of the system. Also, it may be possible to strengthen the
real-time aspects of the method by introducing the concept of a processor and task model
using DFDs.
Summary:
OMT is a very useful, expressive object-oriented analysis and design method. The object model
allows a smooth transition from analysis, through design, to code - especially when systems are
implemented in an OO language such as C++. The dynamic model is very useful for illustrating
the way in which the system responds to events. However, the functional model must be used
with great care in order to avoid distorting the structure of the final application.