You are on page 1of 17

Object-oriented programming

(OOP) Language
Definition & Explanation
Object-oriented programming (OOP) is a programming language
model organized around "objects" rather than "actions" and data rather than
logic. Historically, a program has been viewed as a logical procedure that
takes input data, processes it, and produces output data.
A type of programming in which programmers define not only the data type
of a data structure, but also the types of operations (functions) that can be
applied to the data structure. In this way, the data structure becomes an
object that includes both data and functions. In addition, programmers can
create relationships between one object and another. For example, objects
can inherit characteristics from other objects
The object-oriented paradigm was first conceived in the 1960's and
implemented in languages such as SIMULA-67. One of the initial concerns
with early object-oriented languages was their efficiency. Programs written
using structured languages, such as Pascal and C, executed faster than
programs written using early object-oriented languages. Although programs
which used the object-oriented programming were more extensible and
easier to maintain from a programmer's point of view, an unacceptable price
had to be paid in the program's runtime behaviour. Recently, however, the
runtime execution of object-oriented programs has improved considerably.
This has been due in part to both the development of faster hardware and
the creation of efficient languages and compilers which support object-
oriented programming, such as C++. These facts, in addition to the ever-
increasing accessibility of object-oriented languages to the common
programmer has created a major evolution in the area of software
development.
There is, as yet, no universally agreed upon definition of exactly what
constitutes object-oriented programming. Booch suggests:
``Object-oriented programming is a method of implementation in which
programs are organized as cooperative collections of objects, each of which
represents an instance of some class, and whose classes are all members of
a hierarchy of classes united via inheritance relationships.''

TALHA Maqsood| Object Oriented Programming Languages 1


From this definition, one can infer that object-oriented programming consists
of instantiating a number of objects which communicate with one another so
as to achieve some desired behaviour. This paradigm is natural with how
humans see the world; as a series of cause-effect relationships, where an
action performed on one object has effects on the objects with which it
communicates.
Object-Oriented Programming (OOP), in computer science, type of high-level
computer language that uses self-contained, modular instruction sets for
defining and manipulating aspects of a computer program. These discrete,
predefined instruction sets are called objects and they may be used to
define variables, data structures, and procedures for executing data
operations. In OOP, objects have built-in rules for communicating with one
another. By using objects as stable, preexisting building blocks,
programmers can pursue their main objectives and specify tasks from the
top down, manipulating or combining objects to modify existing programs
and to create entirely new ones
Object-oriented programming (OOP) languages, such as C++ and Java, are
based on traditional high-level languages, but they enable a programmer to
think in terms of collections of cooperating objects instead of lists of
commands. Objects, such as a circle, have properties such as the radius of
the circle and the command that draws it on the computer screen. Classes
of objects can inherit features from other classes of objects. For example, a
class defining squares can inherit features such as right angles from a class
defining rectangles. This set of programming classes simplifies the
programmer’s task, resulting in more “reusable” computer code. Reusable
code allows a programmer to use code that has already been designed,
written, and tested. This makes the programmer’s task easier, and it results
in more reliable and efficient programs.
The programming challenge
The programming challenge was seen as how to write the logic, not how to
define the data. Object-oriented programming takes the view that what we
really care about are the objects we want to manipulate rather than the
logic required to manipulate them.

Object-Oriented Programming Concepts


What Is an Object?

TALHA Maqsood| Object Oriented Programming Languages 2


Objects are key to understanding object-oriented technology. An object is a
software bundle of related state and behavior. Software objects are often
used to model the real-world objects that you find in everyday life. Software
objects are conceptually similar to real-world objects: they too consist of
state and related behavior. An object stores its state in fields (variables in
some programming languages) and exposes its behavior through methods
(functions in some programming languages). Methods operate on an object's
internal state and serve as the primary mechanism for object-to-object
communication. Hiding internal state and requiring all interaction to be
performed through an object's methods is known as data encapsulation —
a fundamental principle of object-oriented programming
Bundling code into individual software objects provides a number of
benefits, including:

1. Modularity: The source code for an object can be written and


maintained independently of the source code for other objects. Once
created, an object can be easily passed around inside the system.

2. Information-hiding: By interacting only with an object's methods, the


details of its internal implementation remain hidden from the outside
world.

3. Code re-use: If an object already exists (perhaps written by another


software developer), you can use that object in your program. This
allows specialists to implement/test/debug complex, task-specific
objects, which you can then trust to run in your own code.

4. Pluggability and debugging ease: If a particular object turns out to be


problematic, you can simply remove it from your application and plug
in a different object as its replacement. This is analogous to fixing
mechanical problems in the real world. If a bolt breaks, you replace it,
not the entire machine

What Is a Class?
A class is a prototype from which objects are created.
What Is Inheritance?
Inheritance provides a powerful and natural mechanism for organizing and
structuring your software. Different kinds of objects often have a certain

TALHA Maqsood| Object Oriented Programming Languages 3


amount in common with each other. Object-oriented programming allows
classes to inherit commonly used state and behavior from other classes. In
the Java programming language, each class is allowed to have one direct
super class, and each super class has the potential for an unlimited number
of subclasses:
What Is an Interface?
An interface is a contract between a class and the outside world. When a
class implements an interface, it promises to provide the behavior published
by that interface. Objects define their interaction with the outside world
through the methods that they expose. Methods form the object's interface
with the outside world; the buttons on the front of your television set, for
example, are the interface between you and the electrical wiring on the
other side of its plastic casing. You press the "power" button to turn the
television on and off.
What Is a Package?
A package is a namespace for organizing classes and interfaces in a logical
manner. Placing your code into packages makes large software projects
easier to manage. The Java platform. A package is a namespace that
organizes a set of related classes and interfaces. Conceptually you can think
of packages as being similar to different folders on your computer. You
might keep HTML pages in one folder, images in another, and scripts or
applications in yet another. Because software written in the Java
programming language can be composed of hundreds or thousands of
individual classes, it makes sense to keep things organized by placing
related classes and interfaces into packages.

Features
There is no formal definition of object-oriented programming. Hence there is
some confusion surrounding what features a programming language must
support in order to claim that it is object-oriented. Despite this, however,
most agree that in order for a language to claim that it is object-oriented, it
must provide support for three major concepts, as inferred from Booch's
definition.
Data encapsulation or data abstraction
Inheritance or derivation
Dynamic or runtime binding

TALHA Maqsood| Object Oriented Programming Languages 4


Encapsulation/Information Hiding
Polymorphism/Dynamic Binding
All pre-defined types are Objects
All operations performed by sending messages to Objects
All user-defined types are Objects

Another especially powerful feature of OOP languages is a property known


as inheritance. Inheritance allows an object to take on the characteristics
and functions of other objects to which it is functionally connected.
Programmers connect objects by grouping them together in different classes
and by grouping the classes into hierarchies. These classes and hierarchies
allow programmers to define the characteristics and functions of objects
without needing to repeat source code, the coded instructions in a program.
Thus, using OOP languages can greatly reduce the time it takes for a
programmer to write an application, and also can reduce the size of the
program. OOP languages are flexible and adaptable, so programs or parts of
programs can be used for more than one task. Programs written with OOP
languages are generally shorter in length and contain fewer bugs, or
mistakes, than those written with non-OOP languages.

Polymorphism
Polymorphism refers to the ability to assume different forms. In OOP, it
indicates a language’s ability to handle objects differently based on their
runtime type. When objects communicate with one another, we say that
they send and receive messages. The advantage of polymorphism is that
the sender of a message doesn’t need to know which class the receiver is a
member of. It can be any arbitrary class. The sending object only needs to
be aware that the receiving object can perform a particular behavior. A
classic example of polymorphism can be demonstrated with geometric
shapes. Suppose we have a Triangle, a Square, and a Circle. Each class is a
Shape and each has a method named Draw that is responsible for rendering
the Shape to the screen. With polymorphism, you can write a method that
takes a Shape object or an array of Shape objects as a parameter (as
opposed to a specific kind of Shape). We can pass Triangles, Circles, and
Squares to these methods without any problems, because referring to a
class through its parent is perfectly legal. In this instance, the receiver is

TALHA Maqsood| Object Oriented Programming Languages 5


only aware that it is getting a Shape that has a method named Draw, but it
is ignorant of the specific kind of Shape. If the Shape were a Triangle, then
Triangle’s version of Draw would be called. If it were a Square, then Square’s
version would be called, and so on.
This is the Title of the Book,
We can illustrate this concept with a simple example. Suppose we are
working on a small graphics package and we need to draw several shapes
on the screen at one time. To implement this functionality, we create a class
called Scene. Scene has a method named Render that takes an array of
Shape objects as a parameter. We can now create an array of different kinds
of shapes and pass it to the Render method. Render can iterate through the
array and call Draw for each element of the array, and the appropriate
version of Draw will be called. Render has no idea what specific kind of
Shape it is dealing with. The big advantage to this implementation of the
Scene class and its Render method is that two months from now, when you
want to add an Ellipse class to your graphics package, you don’t have to
touch one line of code in the Scene class. The Render method can draw an
Ellipse just like any other Shape because it deals with them generically. In
this way, the Shape and Scene classes are loosely coupled, which is
something you should strive for in a good object-oriented design. This type
of polymorphism is called parametric polymorphism, or generics. Another
type of polymorphism is called overloading.

Overloading occurs when an object has two or more behaviors that have the
same name. The methods are distinguished only by the messages they
receive. Polymorphism is a very powerful concept that allows the design of
amazingly flexible applications.
Encapsulation
Programming languages like C and Pascal can both produce object-like
constructs. In C, this feature is called a struct; in Pascal, it is referred to as a
record. Both are user-defined data types. In both languages, a function can
operate on more than one data type. The inverse is also true: more than one
function can operate on a single data type. The data is fully exposed and
vulnerable to the whims of anyone who has an instance of the type because
these languages do not explicitly tie together data and the functions that
operate on that data. In contrast, object-oriented programming is based on
encapsulation. When an object’s state and behavior are kept together, they
are encapsulated. That is, the data that represents the state of the object
and the methods (Functions and Subs) that manipulate that data are stored
together as a cohesive unit.

TALHA Maqsood| Object Oriented Programming Languages 6


Encapsulation is often referred to as information hiding. But although the
two terms are often used interchangeably, information hiding is really the
result of encapsulation, not a synonym for it. They are distinct concepts.
Encapsulation makes it possible to separate an object’s implementation
from its behavior—to restrict access to its internal data. This restriction
allows certain details of an object’s behavior to be hidden. It allows us to
create a “black box” and protects an object’s internal state from corruption
by its clients.
Encapsulation is also frequently confused with abstraction. Though the two
concepts are closely related, they represent different ideas. Abstraction is a
process. It is the act of identifying the relevant qualities and behaviors an
object should possess. Encapsulation is the mechanism by which the
abstraction is implemented. It is the result. The radio, for instance, is an
object that encapsulates many technologies that might not be understood
clearly by most people who benefit from it.
In Visual Basic .NET, the construct used to define an abstraction is called a
class. The terms class and object are often used interchangeably, but an
object is actually an instance of a class. A component is a collection of one
or more object definitions, like a class library in a DLL.

Examples
The most popular OOP language is C++, developed by Bjarne Stroustrup at
Bell Laboratories in the early 1980s. In 1995 Sun Microsystems, Inc.,
released Java, an OOP language that can run on most types of computers
regardless of platform. In some ways Java represents a simplified version of
C++ but adds other features and capabilities as well, and it is particularly
well suited for writing interactive applications to be used on the World Wide
Web.
Simula was the first object-oriented programming language. Java, Python,
C++, Visual Basic .NET and Ruby are the most popular OOP languages
today. The Java programming language is designed especially for use in
distributed applications on corporate networks and the Internet. Ruby is
used in many Web applications. Curl, Smalltalk, Delphi and Eiffel are also
examples of object-oriented programming languages.

Benefits:

TALHA Maqsood| Object Oriented Programming Languages 7


✔ The concept of a data class makes it possible to define subclasses of
data objects that share some or all of the main class characteristics.
Called inheritance, this property of OOP forces a more thorough data
analysis, reduces development time, and ensures more accurate
coding.
✔ Since a class defines only the data it needs to be concerned with,
when an instance of that class (an object) is run, the code will not be
able to accidentally access other program data. This characteristic of
data hiding provides greater system security and avoids unintended
data corruption.
✔ The definition of a class is reuseable not only by the program for which
it is initially created but also by other object-oriented programs (and,
for this reason, can be more easily distributed for use in networks).
✔ The concept of data classes allows a programmer to create any new
data type that is not already defined in the language itself.
✔ One of the principal advantages of object-oriented programming
techniques over procedural programming techniques is that they
enable programmers to create modules that do not need to be
changed when a new type of object is added. A programmer can
simply create a new object that inherits many of its features from
existing objects. This makes object-oriented programs easier to
modify.

The Problem of Classification


One of the major problems encountered by designers of object-oriented
software is classification; that is, finding which classes should be grouped
together under a shared base class. When attempting to perform
classification on the problem space, several issues must be addressed. For
example, the designer must decide which properties should be used to
determine commonality. The classification should also be flexible enough to
permit the introduction of new objects into the system which appear to
belong to neither class nor appear to have properties of several classes.
This is a problem faced by other members of the scientific community as
well. For example, biologists have traditionally divided living beings into two
classes: plants and animals; every living entity must belong to one, and only

TALHA Maqsood| Object Oriented Programming Languages 8


one, of these classes. However, when the euglena, a single-celled being with
chloroplasts, was discovered, it seemed perfectly legitimate to place it in
both classes; hence it defied classification. Also, viruses cannot accurately
be portrayed as either a plant or animal; so they too defy classification
under the plant/animal taxonomy.

Programming Language Comparison


Evaluation and comparison of many popular programming languages. It is
intended to provide very high-level information about the respective
languages to anyone who is trying to decide which language(s) to learn or to
use for as particular project.

Note: N/A indicates that a topic or feature is not applicable to the language.
TALHA Maqsood| Object Oriented Programming Languages 9
Smalltal Pytho Visual
Eiffel Ruby Java C# C++ Perl
k n Basic
Hybrid
Object- Add-On
/ Multi- Partial
Orientatio Pure Pure Pure Hybrid Hybrid Hybrid /
Paradig Support
n Hybrid
m
Static /
Dynami Dynami
Dynamic Static Dynamic Dynamic Static Static Static Static
c c
Typing
Generic
Yes N/A N/A No No Yes N/A N/A No
Classes
Single Single
Single
class, class,
Inheritanc class, Multipl Multipl Multipl
Multiple Single multiple multiple None
e multiple e e e
interfac interfac
"mixins"
es es
Feature
Yes No Yes No No No No No No
Renaming
Method
Overloadin No No No Yes Yes Yes No No No
g
Operator
Overloadin Yes Yes? Yes No Yes Yes Yes Yes No
g
Agents Lambd
Higher
(with a Yes
Order Blocks Blocks No No No No
version Expres (???)
Functions
5) sions
Yes Yes
Lexical Yes Yes
(inline No No No (since Yes No
Closures (blocks) (blocks)
agents) 2.1)
Mark Mark Mark
and Mark and and and Refere Refere Referen
Garbage Sweep Sweep or Mark and Sweep Sweep nce nce ce
None
Collection or Generatio Sweep or or Countin Countin Countin
Generati nal Generati Generati g g g
onal onal onal
Uniform
Yes N/A Yes No No No No No Yes
Access
Class
Variables / No Yes Yes Yes Yes Yes No No No
Methods
Reflection Yes (as Yes Yes Yes Yes No Yes Yes? No
of

TALHA Maqsood| Object Oriented Programming Languages 10


Smalltal Pytho Visual
Eiffel Ruby Java C# C++ Perl
k n Basic
version
5)
public,
public, protecte public,
Protected public, protecte d, protect
Name
Access Selectiv Data, protecte d, private, ed, public,
Mangli None
Control e Export Public d, "packag internal, private, private
ng
Methods private e", protecte "friend
private d s"
internal
Design by
Yes No Add-on No No No No No No
Contract
Implem
Implemen
entation
Multithrea tation- Librarie
- Yes Yes Yes Yes No No
ding Dependen s
Depend
t
ent
Regular Standar Standar Standa
Expression No No Built-in d d No rd Built-in No
s Library Library Library
Pointer
No No No No Yes Yes No No No
Arithmetic
Language All .NET C,
C, C++, C, C++, C, some C, C+ C (via
Integratio C Languag Assem C, C++
Java Java C++ +, Java DCOM)
n es bler
Yes
Built-In
No No? Yes Yes Yes No No? (perlse No
Security
c)

Object-Orientation
Many languages claim to be Object-Oriented. While the exact definition of
the term is highly variable depending upon who you ask, there are several
qualities that most will agree an Object-Oriented language should have:
1. Encapsulation/Information Hiding
2. Inheritance
3. Polymorphism/Dynamic Binding
4. All pre-defined types are Objects
5. All operations performed by sending messages to Objects

TALHA Maqsood| Object Oriented Programming Languages 11


6. All user-defined types are Objects
For the purposes of this discussion, a language is considered to be a "pure"
Object-Oriented languages if it satisfies all of these qualities. A "hybrid"
language may support some of these qualities, but not all. In particular,
many languages support the first three qualities, but not the final three.
So how do our languages stack up?

Eiff Smallta Rub Jav C+ Pytho Per Visual


C#
el lk y a + n l Basic
Encapsulation
Ye Yes
/ Information Yes Yes Yes Yes Yes No Yes?
s ?
Hiding
Ye Yes
Inheritance Yes Yes Yes Yes Yes Yes No
s ?
Polymorphism Yes
Ye Yes
/ Dynamic Yes Yes Yes Yes Yes Yes (through
s ?
Binding delegation)
All pre-
defined types Yes Yes Yes No No No Yes No No
are Objects
All operations
are messages Yes Yes Yes No No No No No No
to Objects
All user-
Ye
defined types Yes Yes Yes Yes No Yes No No
s
are Objects
Eiffel, Smalltalk, and Ruby are all pure Object-Oriented languages,
supporting all six qualities listed above. Java claims to be a pure Object-
Oriented language, but by its inclusion of "basic" types that are not objects,
it fails to meet our fourth quality. It fails also to meet quality five by
implementing basic arithmetic as built-in operators, rather than messages to
objects.
C++ is considered to be a multi-paradigm language, of which one paradigm
it supports is Object-Orientation. Thus, C++ is not (nor does it contend to
be) a pure Object-Oriented language.

TALHA Maqsood| Object Oriented Programming Languages 12


The difference between object-oriented
programming (OOP) and procedure-oriented
programming (POP)
OOP POP
OOPS means Object Oriented In procedural program ,programming
Programming Languages and logic follows certain procedures and
Systems and is different from the the instructions are executed one
Structural programming in after another. In OOPs program, unit
the fact that in OOPS programming of program is object, which is nothing
you take advantage of but combination of data and code.
Polymorphism, Multiple inheritance In procedural program, data is
and Abstraction and exposed to the whole program where
Encapsulation of the data by using as in OOP's program ,it is accesible
Private and this helps in Security of within the object and which in turn
Data while giving you the levarage to assures the security of the
program your software system with code.
the maximum flexibility.
Object Oriented programming deals with Procedural programming focuses on the
the elemental basic parts or building steps required to produce the desired
blocks of the problem, outcome.

TALHA Maqsood| Object Oriented Programming Languages 13


Object Orientation [OO], in general, is a Procedural Programming, by contrast, is
methodology for modeling the real world a methodology for modeling the real
or at least the problem being solved, by world or the problem being solved, by
decomposing the problem into smaller determining the steps and the order of
discrete pieces called "Objects". What those steps that must be followed in
makes an "object" unique is the formal order to reach a desired outcome or
and explicit combination these smaller specific program state. For example,
pieces' behavior with its' data into a consider the problem: "calculate the
single entity. The object's behaviors are month end closing balance for an
called methods in OO terminology, while account." The process is take the
its data is called the Object's state. starting balance, subtract all the debits
"Objects" will make up every part of the and add all the credits for the period and
solution, that is, every part of the then you arrive closing balance. The key
program will be made from objects. point for procedural programming is
Formally, there are technical attributes identification and articulation of the
of that must be present for a program process or steps that must be followed.
(or a programming Language) to be
considered Object Oriented, such as
inheritance, polymorphism,
encapsulation, and protection; aspects of
these terms are still under debate in
many programming circles, so no, 100%
certain, absolutely clear definition is
possible. The core concept, though, is
that an "Object" is binding together of
data and behavior, and Object Oriented
programming, is the use of Objects while
solving the problem.

e.g. e.g.
JAVA VB.NET,C#.NET C, VB, PERL

TALHA Maqsood| Object Oriented Programming Languages 14


The most important differences between
structured and object oreintated programming
and there similarities?
Structured programming OOP Language
Language
Structured programming is OOP adds another level to structured
concerned essentially with finding an programming by creating a layer of
appropriate way to decompose a data encapsulation that is implicit in
problem into smaller problems, and the paradigm of an "object". Objects
to modularize the code in a way that contain (or implement) both data and
makes each small subroutine or the functions that operate on that
function easy to understand and data.
reasonably self-contained.

It also is concerned with the in OOP there is generally a greater


appropriate use of program control level of data-hiding and also some
structures like IF-THEN-ELSE, loops, degree of hiding implementation.
and functions, in order to make
programs easier to understand and
modify.

Structured programming concerns OOP also provides for inheritance,


itself very much with control which facilitates reuse, although it
structures and functions. also can make design decisions
difficult (particularly when multiple
inheritance is desirable).

In general terms, a structured In comparison, object-oriented


programming language is laid out in a languages often contain a set of
series of explicit statements and does reusable modular components, which
not generally contain commands which can be called to execute at various
redirect the execution of statements to points throughout the program, without
other areas of the program. having to be completely rewritten. Some
of the more popular object-oriented

TALHA Maqsood| Object Oriented Programming Languages 15


languages include Java and C++.

There is an advantage to using One of the advantages to using


structured programming when writing object-oriented programming languages
classes and complex functions are not is that it is modular. It is possible to write
necessary. It can take up more time and a reusable piece of code, such as a
energy to develop classes rather than function or a class, which can be used
simply write a straightforward piece of multiple times throughout a program
code, which executes a specific set of without having to rewrite it .This can
commands. It depends on what the save the developer much time and effort
overall purpose of the program is. in the development process.

One of the main disadvantages to One of the possible disadvantages to


using a structured programming using an object-oriented programming
language versus an object-oriented language is its sheer complexity. It is not
language is that it is not ‘modular’. In typically recommended to use object-
other words, the code is not split up into oriented languages when developing
reusable sections. The code is written smaller, less complex programs or
and executed sequentially; therefore you programs that are built to run on low
may have redundant code. It may take powered computers.
longer to develop programs using
structured language.

N/A Considering the potential complexity of a


filing system application, it would
probably be recommended to use object-
oriented technology. Also, being that
application development using object-
oriented languages can be done faster,
this might save the developer’s time so
that they could deliver the program to
the client sooner.

e.g. e.g.
JAVA VB.NET,C#.NET

Similarities

TALHA Maqsood| Object Oriented Programming Languages 16


Many of the same concerns of appropriate modularization, data
encapsulation, program structure, parameter passing, and so on will apply
to both SP and OOP. OOP provides an extra layer of data encapsulation and
a different view of the relationships between data and the functions that act
on the data.

TALHA Maqsood| Object Oriented Programming Languages 17

You might also like