You are on page 1of 28

Introduction

Introduction
Dr Shafiq Hussain
PhD Software Engineering UK

Current Positions:
Project Director,
BZU Sub-Campus Sahiwal
Introduction
HOD Computer Science
Department BZU Sub-Campus
Sahiwal

Director, Distance Education,


BZU Sub-Campus Sahiwal
How to Contact Me?
Email:
shafiqhussain@bzu.edu.pk

Email will be our official way of


communication.

Cell # (only for emergency and


CR)
0322-7075700
Teaching Methodology
Concepts, techniques and tools
Every lecture will be given to you as soft
copy
Ask questions . Your questions will be
answered
Assignments
Written Quizzes
Purely a practical Subject
Always bring your laptop in the class
Object Oriented
Programming
What is Object Oriented
Programming
Object-Oriented Programming (OOP)
refers to a programming
methodology based on objects,
instead of just functions and
procedures.
These objects are organized into
classes, which allow individual
objects to be group together.
What is Object Oriented
Programming
Most modern programming
languages including Java, C++, and
Smalltalk are object-oriented
languages
The prime purpose of C++
programming was to add object
orientation to the C programming
language, which is in itself one of the
most powerful programming
languages.
What is Object Oriented
Programming
The core of the pure object-oriented
programming is to create an object, in code,
that has certain properties and methods.
While designing C++ modules, we try to
see whole world in the form of objects.
For example a car is an object which has
certain properties such as color, number of
doors, and the like. It also has certain
methods such as accelerate, brake, and so
on.
Object
This is the basic unit of object oriented
programming. That is both data and
function that operate on data are
bundled as a unit called as object.
An instance of a class is called an
object. If classes are an abstract
representation of an object, an
instance is its concrete representation.
Objects are the concrete
representation of a class.
Object

A class may have many objects.


An object contains both data and
functions.
The functions, procedures, methods,
actions and behaviors represents the
same thing.
The data, variables, attributes,
properties and class variables
represents the same thing.
Class
When you define a class, you define a
blueprint for an object.
This doesn't actually define any data, but
it does define what the class name
means, that is, what an object of the class
will consist of and what operations can be
performed on such an object.
A class is a template for multiple objects
with similar features. Classes embody all
the features of a particular set of objects.
Class

When you write a program in an


object-oriented language, you dont
define actual objects.
You define classes of objects. At the
time of creation of a class no
memory is allocated to the class.
Memory is allocated when we create
objects of that class.
Class Examples

Person, Student, Tree, Vehicle,


Motorcycle, Furniture, Animal, Book
etc.
Attributes
Attributes are the individual things
that differentiate one object from
another and determine the
appearance, state, or other qualities of
that object. Lets create a theoretical
class called Motorcycle. The attributes
of a motorcycle might include the
following:
Color: red, green, silver, brown
Style: cruiser, sport bike, standard
Make: Honda, BMW, Bultaco
Attributes
Attributes of an object can also include
information about its state; for example,
you could have features for engine
condition (off or on) or current gear
selected.
Attributes are defined by variables; in fact,
you can consider them analogous to
global variables for the entire object.
Because each instance of a class can have
different values for its variables, each
variable is called an instance variable.
Instance Variables
Instance variables define the attributes of
an object.
The class defines the kind of attribute,
and each instance stores its own value
for that attribute.
Each attribute, as the term is used here,
has a single corresponding instance
variable; changing the value of a variable
changes the attribute of that object.
Instance Variables
Instance variables may be set when
an object is created and stay
constant throughout the life of the
object, or they may be able to
change at will as the program runs.
Behavior

A classs behavior determines what


instances of that class do when their
internal state changes or when that
instance is asked to do something by
another class or object.
Behavior is the way objects can do
anything to themselves or have
anything done to them.
For example, to go back to the
theoretical Motorcycle class, here are
some behaviors:
Behavior

Motorcycle class might have:


Start the engine
Stop the engine
Speed up
Change gear
Behavior

To define an objects behavior, you


create methods, which look and
behave just like functions in other
languages, but are defined inside a
class. Java does not have functions
defined outside classes (as C++
does).
Methods

Methods are functions defined inside


classes that operate on instances of those
classes.
Methods dont always affect only a single
object; objects communicate with each
other using methods as well.
A class or object can call methods in
another class or object to communicate
changes in the environment or to ask that
object to change its state.
Methods

Just as there are instance and class


variables, there are also instance and
class methods. Instance methods
(which are so common theyre
usually just called methods) apply
and operate on an instance; class
methods apply and operate on a
class (or on other objects).
Abstraction

Data abstraction refers to, providing


only essential information to the
outside world and hiding their
background details, i.e., to represent
the needed information in program
without presenting the details.
Abstraction

For example, a database system


hides certain details of how data is
stored and created and maintained.
Similar way, C++ classes provides
different methods to the outside
world without giving internal detail
about those methods and data.
Encapsulation

Encapsulation is placing the data and the


functions that work on that data in the same
place. While working with procedural
languages, it is not always clear which
functions work on which variables but object-
oriented programming provides you
framework to place the data and the relevant
functions together in the same object. The
concept of encapsulation is implemented by
creating classes of real world entities.
Inheritance
One of the most useful aspects of object-
oriented programming is code reusability.
Inheritance is the process of forming a new
class from an existing class that is from the
existing class called as base class; new
class is formed called as derived class.
This is a very important concept of object-
oriented programming since this feature
helps to reduce the code size.
Polymorphism
The ability to use an operator or
function in different ways in other
words giving different meaning or
functions to the operators or
functions is called polymorphism.
Poly refers to many. That is a single
function or an operator functioning in
many ways different upon the usage
is called polymorphism.

You might also like