Professional Documents
Culture Documents
CSC- 210
Object Oriented Programming
Lecturer
Sameena Javaid
https://sites.google.com/site/sameenajavaidcs
Bahria University Karachi Campus
LECTURE 3
FUNDAMENTALS OF OOP
OUTLINE
PARADIGM OF OOP
• Programs are divided into entities Known as
classes of objects.
• Major emphasis is on objects rather then
procedures.
• Functions and Data Structures are required to
design characteristics of objects.
• Data hiding is an important feature.
• Objects communicate with each other through
functions.
• New data and functions can be easily added
whenever necessary.
• Follows bottom up approach in program design.
Bahria University Karachi Campus
Data Encapsulation
It is wrapping of
data and
associated
functions in one
single unit.
Data Abstraction
It is the act of
representing the
essential features
without including the
background details.
(Masking the
unwanted data from
user)
Bahria University Karachi Campus
Inheritance
It is the concept of
one class to inherit
properties from other
class.
Polymorphism
It is the ability for
data to be
processed in more
than one form.
Bahria University Karachi Campus
OBJECTS
• Objects are the basic run-time entities of an object
oriented system.
• They may represent a person, a place or any item
that the program must handle.
• Example
Representation of an object
Bahria University Karachi Campus
OBJECTS
Objects are made up of two "things":
CLASS
1. Class is a blueprint of object(s).
2. Objects created from the same class are similar but
not the same.
3. The objects are similar because each has similar
property type.
4. Each is different because the property value is
different.
5. Analogy:
a. Cars built and assembled based on the same
blueprint will definitely look similar in design.
However each car differs in serial numbers,
configuration, appearance, etc.
Car
blue
print Actual
CLASS cars
OBJECT(S)
Bahria University Karachi Campus
CLASS SYNTAX
1. We know a classname if there is keyword “class” before the
name.
2. The body of the class is enclosed in curly braces { }.
3. Hence, the syntax of a class is: <access specifier>class ClassName{}
Class Activity:
Can I use
Car.engineNo = “MGH05GX100085”;
Why and why not?
Bahria University Karachi Campus
MESSAGE PASSING
• A message for an object is a request for execution of a
procedure and therefore will invoke a function in the
receiving object that generates the desired result.
• Message passing involves specifying the name of the
object, the name of the function i.e. message and the
information to be sent.
• Objects can communicate with each other by passing
messages same as people pass messages to each
other.
• Objects can send or receive messages or information.
• Concept of message passing makes it easier to talk
about building systems that directly model or simulate
their real-world counterparts.
Bahria University Karachi Campus
MESSAGE PASSING
• For example, consider two classes Product and
Order. The object of the Product class can
communicate with the object of the Order class
by sending a request for placing order.
Bahria University Karachi Campus
MOVING TOWARDS
OBJECT-ORIENTED
PROGRAMMING
Bahria University Karachi Campus
ENCAPSULATION
• Encapsulation is the principle of object-oriented
programming.
• In simple words, “Encapsulation is a process of
binding data members (variables, properties) and
member functions (methods) into a single unit”.
• The data is not accessible to the outside world,
and only those functions which are wrapped in
the class can access it.
• These functions provide the interface between the
objects data and the program. This insulation of
the data from direct access by the program is
called data hiding or information hiding.
• A Class is the best example of encapsulation.
Bahria University Karachi Campus
ABSTRACTION
• Abstraction refers to the representation of
necessary features without including details or
explanations.
• Classes use the concept of abstraction and are
defined as a list of abstract attributes and
functions to operate on these attributes.
• Data abstraction is a programming (and design)
technique that relies on the separation of
interface and implementation.
• Implementation denotes how variables are
declared, how functions are coded, etc. It is
through interface (function header/function
signature) a communication is sent to the
object as messages.
Bahria University Karachi Campus
ABSTRACTION
• When you press a key on your
keyboard the character appears on
the screen, you need to know only
this, but How exactly it works
electronically, is not needed.
INHERITANCE
• Inheritance is the process by which
object of one class acquire the
properties of objects of another class.
• In OOP, the concept of inheritance
provides the idea of reusability. This
means that we can add additional
features to an existing class without
modifying it.
• This is possible by deriving a new class
from the existing one. The new class will
have combined features of both the
classes.
• Which in turn will increase the quality of
work and productivity.
Bahria University Karachi Campus
POLYMORPHISM Poly
(Many)
Morphism
(Forms)
Polymorphism
(Many Forms)
POLYMORPHISM
• Same way functions can be overloaded.
• For example, sum()function may take two
arguments or three arguments etc.
• i.e. sum (5, 7) or sum (4, 6, 8).
• Single function Draw() draws different objects.
Bahria University Karachi Campus