Vous êtes sur la page 1sur 24

Object Oriented

Programming
BY: IRFAN U. MEMON
B.E (SOFTWARE ENGINEERING)
MEHRAN UET. JAMSHORO

Prerequisites
Foundations of Programming
Programming Fundamentals

Outlines
Programming Paradigms
Object Oriented Programming
(OOP)?
Need of OOP
Classes
Objects

Programming Paradigms

Aprogramming paradigmis a fundamental


style of computer programming, a way of
building the structure and elements of
computer programs.

Two Programming Paradigms

Structural Programming
Object Oriented Programming.

Data
Logic

Data
Logic

Data
Logic

What Object Orientation is ?


Programming Paradigm
Not a programming Language.
Set of Ideas that is supported
by many programming
e.g C++, Java, C#, Php, Objective-C (Many
languages.
others)
Object Oriented Programming Languages.

Object Oriented Programming


(OOP)

What is An Object?
What are object in real world?
Things
Is this desk?
This Computer?
A Pen?

They are all objects, these are


all things.

Objects are separate from one


another
They have their own existence

Objects have Attribute


A computer can be on or of
A pen can be blue or blue

These are the attributes of any


object
Things like color, weight, and size
They describe the current state of an Object

Objects in Computer
Objects are instances of Class.
Things that have Identity, Attribute &
behavior.
An object is basically a block of
memory that has been allocated and
configured according to the blueprint

Objects in Computer
An object is anything that can be
modelled as data (properties) and
operations on that data (methods).

In real world Objects are


tangible things
Where as in computers
objects can be intangible
things
also
Balance: Rs:
Name: Ali
Name: Saba
15000
Number: 36-5
Deposite()
Withdraw()
Bank Account Object

Gender: Male
walk()
talk()

Gender: Female
walk()
talk()

Person Object

Person Object

What is a Class?

Class
Classes are templates or
blueprints which are followed to
create an Object.
A detailed description or
definition.
A is not an object it self.

What does a class


Describe
Attributes
name
Height
Weight
Gender
age

Behavior
Walk
Run
Jump
Speak
sleep

What does a class


Describe
Properties
name
Height
Weight
Gender
age

Methods
Walk
Run
Jump
Speak
sleep

Object Oriented
Paradigm
Abstraction
Polymorphism
Inheritance
Encapsulation

Abstraction

Focus on the essentials


Ignore the Irrelevant
Ignore the unimportant
Not the separate class, one
generalized class
Focuses on how our class
would look like rather than

Encapsulation
Idea of surrounding something
Bundling the attributes and
behavior in the same class.
Also want restrict access in or
out of the class. (Data Hiding)
Black Boxing.
Why Hiding?

Inheritance
Creating a class based on
another class
Code Re-use
Base Class is know as Super
class
New formed class as Child
Class

Polymorphism
Poly Many, morph shapes
It enables us automatically do
the correct behavior even if
what we are working with can
many forms.
take
(+) sign

Methods

method is a code block that contains a series of


statements
Every C# program has at least one class with a
method
main
method
To Use method we need two things
Defining a Method
Calling a Method

Defining Methods in C#
The syntax for defining a method in C# is as follows
<Access Specifier> <Return Type> <Method Name>
(Parameter List)
{
Method Body
}

Types of Methods
Procedure
A method is known as procedure if it does not return
any value
OR
If its return type is void
Function
A method is known as function if it do returns any
value
OR
If its return type is not void

Vous aimerez peut-être aussi