Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
30 views

01chapter One - Introduction To OOP

Uploaded by

tasheebedane
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

01chapter One - Introduction To OOP

Uploaded by

tasheebedane
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

CHAPTER-ONE

Introduction to Object-Oriented Programming


Outline
 Programming Paradigm

 Type of Programming Paradigm

 Procedural programming vs Object Oriented Programming

 Overview OOP principles


Encapsulation
Inheritance
Polymorphism
PROGRAMMING PARADIGMS
 Fundamental approaches to solving problems and structuring
code, each offering unique methodologies and principles for
software development.

There are lots for programming language that are known


• but all of them need to follow some strategy when they are
implemented and this methodology/strategy is paradigms.
 how tasks to be carried out on a computer should be structured and
organized.
 Style and strategy programming language follows to solve problem
TYPES OF PROGRAMMING PARADIGM

Apart from varieties of programming language there are lots of


paradigms to fulfill each and every demand.

We can distinguish between two types of programming


paradigm:
i. Declarative programming paradigm

ii. Imperative programming paradigm


I . DECLARATIVE PROGRAMMING PARADIGM
Declarative - specify what to do, not how to do it

Users concentrate on defining input and output rather than the program steps
required

 Declarative programming examples are CSS, HTML, XML, SQL, Prolog etc.

 E.g.: HTML describes what should appear on a web page, not how it should be
drawn on the screen.

 Declarative programming is a style of building programs that expresses logic of


computation without talking about its control flow.

Declarative programming paradigm- is divided as Logic, Functional, and


Database
DECLARATIVE : LOGIC, FUNCTIONAL, AND DATABASE

Logic programming paradigms


 It can be termed as abstract model of computation.

 It would solve logical problems like puzzles etc

 The execution of the program is very much like proof of mathematical statement, e.g., Prolog

Functional programming paradigms:


 the execution of series of mathematical functions.

 Function can be replaced with their values without changing the meaning of the program. E.g
perl, javascript mostly uses this paradigm.

Database/Data driven programming approach –


 This programming methodology is based on data and its movement.

 Program statements are defined by data rather than hard-coding a series of steps.

 Eg. SQL
WHY YOU SHOULD USE DECLARATIVE
PROGRAMMING?

 Reusability-
 Not rewriting code can speed up the program you are currently
writing and any others that use the same functionality in the future.

 Reducing Errors:
 the chances of errors arising are smaller and it allows for your
application to become more stable.
POTENTIAL DRAWBACKS OF
DECLARATIVE PROGRAMMING
Lack of Control:

 In declarative programming, you may use functions that someone else created,
in order to achieve the desired results.
 But you may need specific things to be completed behind the scenes to make
your result come out properly.

Inefficiency:

 When the implementation is controlled by something else, you may have problems

making your code efficient.

 In applications where there may be a time constraint, you will need to program the

individual steps in order to make sure your program is running as efficient as possible.
ii. Imperative programming paradigm
A programming language that requires programming discipline such as C/C++,
Java, COBOL, FORTRAN, Perl and JavaScript.

Imperative - specify both what and how-to knowledge


 int x; - what (declarative)

 x=x+1; - how

This is the form and style of programming in which we care about how we get to
an answer, step by step.

We want the same result ultimately, but we are telling the complier to do things a
certain way in order to achieve that correct answer we are looking for.
EXAMPLE
 To give directions in an imperative fashion, you say, “Go to 1st Street, turn left
onto Main, drive two blocks, turn right onto Maple, and stop at the third
house on the left.” The declarative version might sound something like this:
“Drive to Sue’s house.” One says how to do something; the other says what
needs to be done.

 Example#2: Average of five number in C++


int marks[5] = { 12, 32, 45, 13, 19 }
int sum = 0;
float average = 0.0;
for (int i = 0; i < 5; i++) {
sum = sum + marks[i];
} average = sum / 5;
IMPERATIVE PROGRAMMING PARADIGM …

Imperative programming is divided into:

a) Procedural programming,

b) Object Oriented Programming


PROCEDURAL PROGRAMMING
A procedural Programming language follows a sequence of
instructions and tells the computer what to do step- by-step.

Procedural programming depends on procedures.

Top Dowd approach


 if a change is required to the program, the developer has to change every line
of code that links to the main or the original code.

Examples for procedural programming languages include C, COBOL,


FORTRAN and VB.
OBJECT ORIENTED PROGRAMMING

 OOP is a programming paradigm that uses the concept of


classes and objects to construct models based on the real
world surrounding.

An object is a constituent of a program that recognizes


how to execute certain actions and how to interrelate with
other elements of the program.

 More emphasis is on data rather procedure.


OBJECT ORIENTED PROGRAMMING …
Objects are the foundation of object-oriented programming.

An OOP uses a set of objects, which will communicate by sending and
receiving messages to request services or information.

A class is a collection of objects with similar properties and


• A simple example of an object would be a person.

• Logically, you would expect a person to have a name. This would be considered a property of the person.

• You would also expect a person to be able to do something, such as walking. This would be considered a
method of the person.

A method in OOP is like a procedure in procedural programming.


OBJECT ORIENTED PROGRAMMING …

Finally, an object or a collection of objects (class)


attempts to complete its goals (goals such as displaying
‘hello world’ on to the screen) by communicating by
swapping messages.

Some examples for Object-Oriented Programming


languages include Java, C#, .NET, C++, Python and
Perl.
COMPARING OOP VS PROCEDURAL PROGRAMMING

OOP Procedural Programming

Based on object and classes Based on procedure

Bottom up approach Top –down approach

Object can move and communicate with Data cannot be moved liberally from
each other through member functions function to function

More secure Divided in to functions

Does not allow global data but instead, Less secure


 Uses access modifiers(e.g. private,
Global data for sharing data within
public)
functions(i.e. does not have access
Easy approach to add new data and modifiers)
function
It is quite difficult to add new data
COMPARING OOP VS PROCEDURAL PROGRAMMING

OOP Procedural Programming

Object 2 MAIN GLOBAL


Object 1
PROGRA DATA
M
Data Data

Function Function
FUNC FUNCTI FUNCTION
TION 1 ON 2 3

Object 3

Data
FUNCTION FUNCTION
Function 4 5
OVERVIEW OF OOP CONCEPTS

All OOP languages provide mechanisms that help you


implement the object-oriented model.

 They are:
Encapsulation,

Inheritance, and

Polymorphism.
ENCAPSULATION
Encapsulation: Hiding implementation details of an object from its
clients.

Encapsulation making the fields in a class private and providing access


to the fields via public methods.
 To relate this to the real world, consider the automatic transmission on an
automobile. It encapsulates hundreds of bits of information about your engine, such
as how much you are accelerating, the pitch of the surface you are on, and the
position of the shift lever. You, as the user, have only one method of affecting this
complex encapsulation: by moving the gear-shift lever.
WHY NEED ENCAPSULATION?
Combining data and how it's manipulated in one place:

Hiding the details of how the object works


 The only part of the object that is accessible to the outside world is its
behaviors.
 What happens inside those behaviors and how the state is stored is
hidden from view. E.g.

Protects an object from unwanted access by clients.


 A bank app forbids a client to change an Account's balance.
INHERITANCE
As the name suggests, inheritance means to take something that
is already made.

It is one of the most important of OOP

It is the concept that is used for reusability purpose

Inheritance: is the process by which one object acquires the


properties of another object.
 i.e. Is the mechanism through which we can derived classes from other class
INHERITANCE….
 it supports the concept of hierarchical classification.

In inheritance,
 the derived class is called class or the subclass or we can say the extend
class

The class from which we are deriving the subclass is called the base class
or the parent class

By use of inheritance, an object need only define those qualities that
make it unique within its class.

 It can inherit its general attributes from its parent.


EXAMPLE: CLASS HIERARCHY

 mammals subclass of animals, where


animals are referred to as mammals’
superclass.

 Since mammals are simply more precisely


specified animals, they inherit all of the
attributes from animals.

 A deeply inherited subclass inherits all of the


attributes from each of its ancestors in the
class hierarchy.
POLYMORPHISM
Polymorphism (Greek, meaning “many forms”) is a feature that allows one
interface to be used for a general class of actions.
 Consider a stack (which is a last-in, first-out list). You might have a
program that requires three types of stacks. One stack is used for integer
values, one for floating-point values, and one for characters. The
algorithm that implements each stack is the same, even though the data
being stored differs.

In a non–object-oriented language, you would be required to create three


different sets of stack routines, with each set using different names.
POLYMORPHISM…
More generally, the concept of polymorphism is often expressed
by the phrase “one interface, multiple methods.”
• This means that it is possible to design a generic interface to a
group of related activities.

 This helps reduce complexity by allowing the same interface to


be used to specify a general class of action.
THE BENEFITS OF OOP
Inheritance saves time (Reusability).

Encapsulation (hiding of data) helps with the building of more


secure

User defined data types can be easily constructed.

 Large complexity in the software development can be easily


managed.

OO systems can be easily upgraded from small to larger systems.

Software complexity can be easily managed.


End of Chapter-One

Question? ?

You might also like