CS304 IMP Short Notes
CS304 IMP Short Notes
cs304
What is Abstraction?
hat is a constructor?
A Historical Interlude
Data types
Up to this point in your use of C++, you've used only the basic
types of variables : int, float, bool, double, and so forth.
These are called simple data types. However, they are very
linear in what we can 'model' with them. Let's take an
example. Let's say we wanted to represent a real life object,
say a house. Obviously, we would have to examine the various
attributes of a house : the number of rooms it has, its street
number and whether or not it has a garden (okay, so there are
more attributes, but I won't go into them now). In C++, we
could show the house like this:
History of oop?
you can’t make a call without having mobile. Now what is data
hiding?
Every mobile has inbuilt camera. But still there are another
apps which let us take photos like Retrica.
https://www.youtube.com/channel/UCbIedEXkM13ynuI1sNAI
1cA
Hope this short yet crispy explanation help you to clear your
OOPS concepts…
“some of from”
Advantages of OOP:
What is coop ?
25 | P a g e
What is object?
What is Object-Orientation?
It is a technique in which we visualize our programming
problems in the form of
objects and their interactions as happen in real life.
What is a Model?
A model is an abstraction of something real or conceptual.
We need models to understand an aspect of reality.
Objects
Ali, Car, House, Tree
Interactions
Ali lives in the house
Ali drives the car
27 | P a g e
Object-Orientation - Advantages
As Object Oriented Models map directly to reality as we have
seen in examples
above therefore,
We can easily develop an object-oriented model for a
problem.
Everyone can easily understand an object-oriented model.
We can easily implement an object-oriented model for a
problem using any object
oriented language like c++ using its features1 like classes,
inheritance, virtual
functions and so on…
What is an Object?
An object is,
1. Something tangible (Ali, School, House, Car).
2. Something conceptual (that can be apprehended
intellectually for example
time, date and so on…).
Summary:
• Model is the abstraction of some real word scenario. It helps
us to understand
that scenario.
• Object oriented model of any scenario (problem) describes
that scenario
(problem) in the form of interacting objects.
28 | P a g e
#include<iostream>
class sonu
//data members
strings name;
int age;
string address;
float height;
//functions
public:
void walk()
cout<<"i am walking";
void eating()
30 | P a g e
cout<<"i am eating";
};
int main ()
system("PAUSE");
return 0;
}
31 | P a g e
Classy!
class house
{
public:
int number, rooms;
bool garden;
};
main()
{
house my_house;
32 | P a g e
my_house.number=40;
my_house.rooms=8;
my_house.garden=1;
return 0;
}
Lecture No.02
Information Hiding:
are necessary for the outside world and hiding all other
details from the outside world.”
following principles,
34 | P a g e
Encapsulation
Encapsulation means “we have enclosed all the characteristics
of an object in the object
itself”
35 | P a g e
we can say that Data and Behavior are tightly coupled inside
an object and both the information structure and
implementation details of its operations are hidden from the
outer world.
You can see that Ali stores his personal information in itself
and its behavior is
also implemented in it.
Now it is up to object Ali whether he wants to share that
information with
outside world or not. Same thing stands for its behavior if
some other object in
real life wants to use his behavior of walking it can not use it
without the
permission of Ali.
Advantages of Encapsulation
The following are the main advantages of Encapsulation,
a. Simplicity and clarity
As all data and functions are stored in the objects so there is
no data or function
around in program that is not part of any object and is this
way it becomes very
easy to understand the purpose of each data member and
function in an object.
b. Low complexity
As data members and functions are hidden in objects and each
object has a
specific behavior so there is less complexity in code there will
be no such
situations that a functions is using some other function and
that functions is
using some other function.
c. Better understanding
Everyone will be able to understand whole scenario by simple
looking into object
diagrams without any issue as each object has specific role
and specific relation
with other objects.
Interface :
37 | P a g e
Implementation
Question
What is the difference between an Object Model Diagram and a Class Diagram in IBM
Rational Rhapsody?
39 | P a g e
Cause
You may want to understand which diagram is more suitable as per your requirement.
Answer
Class diagram is a graph of classifier elements connected by their various static
relationships. A “class” diagram may also contain interfaces, packages, relationships,
and even instances,
such as objects and links. Perhaps a better name would be “static structural diagram”,
but “class diagram” is shorter and well established.
Object diagram on the other hand is a graph of instances, including objects and data
values. A static object diagram is an instance of a class diagram. It shows a snapshot of
the detailed state of a system at a point in time. The use of object diagrams is fairly
limited, mainly to show examples of data structures.
The actual differences lie in their purpose. A Class diagram shows your classes and
their relationships. An Object Model Diagram shows the interaction between objects at
some point, during run time.
The actual differences lie in their purpose. A Class diagram shows your classes and their
relationships. An Object Model Diagram shows the interaction between objects at some point,
during run time.
A Class Diagram will show what the Objects in your system consist of (members) and what they
are capable of doing (methods) mostly static. In contrast, an Object Diagram will show how
objects in your system are interacting with each other at some point in time, and what values
those objects contain when the program is in this state.