Você está na página 1de 18

Programming Paradigm

Object oriented

Definition
Object-orientated programming (OOP) is
a programming paradigm that uses
objects and their interactions to design
applications and computer programs.

Characteristics
Encapsulation
This is the mechanism that binds data
structures and the methods (procedures)
which act on them, thus keeping them
together. It is based on the principle of
information hiding, which is the hiding of
design decisions in a computer program
that are most likely to change, thus
protecting other parts of the program from
change if the design decision is changed.

Characteristics
Encapsulation
Moreover it refers to the ability to provide
users with a well defined interface to a set of
functions in a way which hides their internal
workings.
Eg:
shape
myshape;
Here myshape is declared as a variable of the
class shape.

Characteristics
Inheritance
This is a way of forming new classes
using classes that have already been
defined. The new classes, known as
derived classes, inherit or derive their
attributes from the pre-existing classes,
which are referred to as base classes or
ancestor classes. It is intended to help
reuse the existing code with little or no
modification.

Inheritance
In the following example, class person is
a base class and classes MathsTeacher
and Footballer are derived from Person.

Characteristics
Polymorphism
Poly means many. Morphism means
forms.
Polymorphism refers to a programming
languages ability to process objects
depending on their data type or class. In
other words the feature enables classes
to provide different implementation of
methods having the same name.

Characteristics
Polymorphism
For example, given a base class shape,
polymorphism enables the programmer
to define different area methods for any
number of derived classes such as cirlces
rectangles and triangles.
No matter what shape an object is,
applying the area method to it will return
the correct results.

Characteristics
Modularity
Modularity refers to the concept of
increasing the extent to which software is
composed from separate parts, called
modules. Multiple modules are made
first then they are linked and combined
to form a complete sytem. Modularity
enables re-usability and minimizes
duplication.

Advantages of Object Code


Programming

Code Reuse and Recycling: The ability


to re-use the same code at different
places in the program without copying
it.
Easy Tracking of Program Flow: An
easier way to keep track of program
flow than a collection of GOTO or
JUMP statements which can turn a
large, complicated program into
spaghetti code.

Advantages of Object Code


Programming

Encapsulation: Once an object is


created, knowledge of its
implementation is not necessary for its
use unlike older programs. Therefore
coders need not understand the details
of a piece of code before using it. In
addition, objects have the ability to hide
certain parts of themselves. Hence, this
prevents programmers from tampering
with values they shouldnt.

Advantages of Object Code


Programming

Encapsulation Contd: additionally the


object controls how one interacts with
it, preventing other kinds of errors. For
example, a programmer cannot set the
width of a window to -400.

Advantages of Object Code


Programming

Design benefits: Large programs are


very difficult to write. Object
Orientated Programs force designers
go through an extensive planning
phase, which makes for better designs
with less errors. In addition, once a
program reaches a certain size, Object
Orientated Programs are actually
easier to program than non-Object
Orientated ones.

Advantages of Object Code


Programming

Software Maintenance: Object


Orientated Programs are actually much
easier to modify and maintain than a
non-Object Orientated Program. So
although a lot of work is spent before
the program is written, less work is
needed to maintain over time.

Disadvantages of Object
Code Programming

Size: Object Orientated programs are


much larger than other programs. In
the early days of computing, space on
hard drives, floppy drives and in
memory was at a premium. Today we
do not have these restrictions.

Disadvantages of Object
Code Programming

Effort: Object Orientated programs


require a lot of work to create.
Specifically a great deal planning goes
into an object orientated program well
before a single piece of code is written.
Initially, this early effort was felt by
many to be a waste of time. Moreover
since the programs were larger coders
spent more time actually writing them.

Disadvantages of Object
Code Programming

Speed: Object Orientated Programs are


slower than other programs, partially
because of their size. Other aspects of
Object Orientated Programs more
system resources, thus slowing the
program down.

Sample of Code