You are on page 1of 9

Chapter 1

Thinking Object Oriented


**Object Oriented Programming a new paradigm**
 Programming paradigm is a way of conceptutalizing what it means to perform
computation and how tasks to be carried out on a computer should be structured and

om
organized.
 The style of problem solving in object oriented technique is frequently the method used
to address problems in everyday life.

.c
 So,computer novices are often able to take the basic ideas of OOP easily rather than

t
computer literate who are often blocked by their own preconceptions.

po
 OOP treat data as a critical element in program and doesn’t allow it to flow freely
around the system.It ties data more closely to a function that operate on it.The data of

gs
an object can be accessed only by the function associated with that
object.However,function of one object can access function of another object.
lo
Object A 0bject B
.b

Data communication data


eb

Function function
ew
od

Communication Communication
dc

Object C
m

Data

fucntion

fig:Organization of data and function in OOP.

1 Compiled By Er.Shraddha Parajuli


**A way of viewing a world **
How we might go about handling a real world situations and then ask how we could make the
computer more closely model the techniques employed.
Everything in the universe can be seen as object.eg:I wish to send some flowers to my mom for
her birthday.She lives in city X(far away),so my picking the flowers and carrying them to her is
not possible.Inspite,sending her the flower is the easiest task.I only go down to my local
florist,tell her the kinds and numbers of flowers I want to send and my mom’s address too.Then

om
I can be assured the flowers will be delievers.

Agents,Responsibilty ,Messages and Methods:

.c
 Mechanism to solve the problem(flower delievering) was to find an appropriate agent

t
and to pass her a message containing my request.It is the responsibility of florist to

po
satisfy my request.There is some method,some algorithm or set of operations used by
florist to do this.I donot need the particular method she will use to satisfy my request


sight). gs
also I donot want to know the details(i.e. the information is usually hidden form my

So,first principle of OOP solving is the vehicle by which activities are inititated.
lo
 Action Is initiated in OOP by the transmission of a message to an agent(an
.b

object)responsible for the action.The message encodes the request for an action and is
supported by any additional information(arguments) needed to carry out request.The
eb

receiver is the agent to whom the message is sent.If the receiver accepts the message,it
accepts the responsibility to carry out the indicated action.In response to the
message,the receiver will perform some method to fulfill the request.
ew

 A fundamental concept in OOP is to describe behavior in terms of responsibilities .


 My request for action indicates only the desired outcome(flower to my mom ).The
od

florist is free to adopt any technique that achieves the desired result and is not
hampered by interference from my part.
 So, discussing a problems in terms of responsibilities increases the level of abstraction.
dc

 This allows greater independence between agents in solving complex problems.


m

**Description of OOP given by Alan Kay**


 Everything is an object.
 Computation is performed by objects communicating(i.e. sending and receiving
information)with each other, requesting for certain actions.
 Each object has its own memory.
 Every object is an instance of a class. A class simply represents grouping of similar
objects.

2 Compiled By Er.Shraddha Parajuli


 Class is the responsibility for behavior associated with an object i.e. all objects that are
instances of the same class can perform the same actions.
 Classes are organized into a singly rooted tree structure,called the inheritance hierarchy.
Memory and behavior associated with instances of a class are automatically available to
any class associated with a descendant in this tree structure.

**Computation as simulation**

om
View of programming represented by the example of sending flowers to mom is very
different form the conventional convention of a computer.
 The traditional model describing the behavior of a computer executing a program is a
process state or pigeon-hole model.

.c
 In this pigeon-hole model, computer is a data manager, following some pattern of

t
instructions,wandering thorugh memory ,pulling values out of various memory

po
addresses,transforming them and pushing the results back into other slots.By examining
the values in the slots ,we can determine the state of machine or the results produced by


a computation.
gs
Disadvantages/limitaions of the pigeon-hole model is that it is difficult to understand how
to solve problems using the computer.
lo
 In Object Oriented(OO) framework we never mention memory address,variables
.b

,assignment or any other programming terms. Instead,we speak of object,messages and


responsibility for some action.
eb

The power of metaphor


One benefit of the use of OO techniques is the power of metaphor(metaphor means a
thing regarded as a representative or symbolic of something).When [rogrammers think
ew

about problems in terms of behaviors and responsibility of objects they bring with them
a wealth of intuition ,ideas and understanding from their everyday experience.
od

Avoiding Infinite Regression


 Objects can’t always respond to a message by politely asking another object to perform
some action. The result would be an infinite circle of requests(like two man politely
dc

waiting for other to go first before entering a door way).


 Thus, to avoid regression ,at some point,at least a few objects need to perform some
m

work besides passing on the requests to another agents.

**Coping with Complexity**


 At infancy time of computing most program were written in assembly language but a
single individual(which not considers as todays standards)
 Reasons for complexity :

3 Compiled By Er.Shraddha Parajuli


1. Difficulty to remember all the information needed to know in order to develop or
debug their software like :
 Which values were contained in what registers.
 What variables needed to be initialized before? What sorts of control could
be transferred to another section of code?
 The introduction to high level language because of peoples expectation of
what a computer could do.

om
Non-linear behavior of complexity
 A task that would take one programmer two months to perform could not be
completed by two programmers working for one month.

.c
 In Fred’s Brooks memorable phrase:”The bearing of child takes nine months

t
no matter how many women are assigned to the task”.

po
 Reason for this non-linear complexity are:
1. The interconnections between software components were
complicated.
gs
2. Large quantities of information had to be communicated among the
various members of the programming team.
lo
3. An individual section of code can’t be understood by only a single
.b
person in the team.
eb

Abstraction Mechanism(Mechanism use to control complexity)


The ability to encapsulate and isolate design and execute information.
ew

->>Process in abstraction mechanism:


od

a)Procedure and function:Procedure and function are main two first abstraction mechanism
to be widely used in programming language.They allowed task that were executed repeatedly to
be collected in one place and reused rather than being duplicated several times.
dc

Libraries of procedures and function provided first hint of information hiding.They permit
programmer to think about operation in high level terms,emphasizing on what is being done,not
m

it is being implemented.

b)Block Scoping:Nesting of function(one function inside another) to solve problem associated


with procedure and function ,the idea of block and scoping was introduced which permits
functions to be nested.
This is also not truly the solution.If a data area is shared by two or more procedure ,it must still
be declared in more general scope than procedure.

4 Compiled By Er.Shraddha Parajuli


Eg:
int sum(){
int a,b;
……….
………

om
int mul(){
….

.c
……
}

t
po
}
Partially solved the abstraction mechanism

gs
c)Modules:It is basically a mechanism that allows the programmers to encapsulate a collection
lo
of procedures and data and supply both import and export statement to control visibility feature
from outside modules.
.b

Parna’s principle for creation and use of modules:


eb

 One must provide the intended user with all the information needed to use the module
correctly and nothing more.
ew

 One must provide the implementor with all the information needed to complete the
module and nothing more.
od

d)Abstract data type(ADT):



dc

To solve instantiation,the problem of what to do,your application needed more than one
instance of software abstraction.The key to solve this problem is ADT.
 ADT is simply programmer defined data type that can be manipulated in a manner similar
m

to system provided data types.


 This supported both information hiding as well as creating many instance of new data
type.

e)Objects,Messages,Inheritance and Polymorphism:


OOP added new ideas to the concept of ADT.

5 Compiled By Er.Shraddha Parajuli


 Inheritance allows different data types to share the same code,leading to a reduction in
code size and an increase in functionality.
 Polymorphism allows this shared code to be designed to fit the specific circumstances of
individual data types.

**Types of Classes**
There are different types of classes as mentioned below:

om
1. Data Managers:It is sometime called Data or State classes with the principal
responsibility of maintaining data or state information of one sort or another.For eg:in an

.c
abstraction of playing card,a major task for the class Card is simply to maintain the data
values that describe rank and suit.They are often recognizable as the nouns in the

t
po
problem description and are usually the fundamental building of a design.
2. Data sinks or data sources: These are the classes that generates data,such as random
number generator so that accept data and then process them further such as classs

gs
performing to a disk or file. Unlike a data manager, a data sink or data source does not
hold the data for any period of time, but generated it on demand or processes it when
lo
called upon.
3. View or observer classes: An essential portion of most application is the display of
.b

information on an output device such as terminal screen because the code for performing
eb

this activity is often complex, frequently modified and largely independent of the actual
data being displayed , it is good programming practice to isolate display behavior in class
other then those that maintain the data being displayed.
ew

4. Facilitator or Helper classes: These are the classes that maintain little or no state
information themselves but assist in the execution of complex task. For eg:- in displaying
a playing card image we use the services of a facilitator class that handles the drawing of
od

the lines and text on the display device.


dc

Definition of OOP
m

OOP is a programming paradigm based upon objects(having data + methods) that aims to
incorporate / provide the advantage of modularity and reusuability.

Definition of C++
C++ is an OOP language developed by Bjarne Stroustrup at AT&T Bell Laboratories in Murray Hill,
New Jersey , USA in early 1980’s.

6 Compiled By Er.Shraddha Parajuli


C++ is an extension of C with a major addition of class construct feature of Simula67 known as C
with classes.

Definitions of Object
It is defined as an instance of class that are used to interact with one another to design application
and computer programs. It has two components they are:

 attributes (data)

om
 behavior (functions).

.c
**Difference between Structured and Object Oriented Programming**

t
Structured/Procedure Oriented Object Oriented Programming

po
Programming

1.Program is represented as logical 1.Program is the collection of objects that


structure.
gs
communicate with each other
2.Designed which focuses on process or 2. Designed which focuses on only the data
lo
logical structure and then data required required.
.b

for that process(importance is given to


3. It follows bottom-up approach.
function and sequence of the actions to
eb

be done). 4. It is more secure as it implements the


feature of data hiding.
3. Follows top-down approach
ew

5. Provides more re-usuability and less


4. It is less secure as there is no use of data
function depenedency.
hiding.
6. Abstraction and Flexibility is highly
od

5. Provide less re-usuability, more


supported.
function dependency.
7. Eg:- C++, C#, Java, PHP, etc.
dc

6. Abstraction and Flexibility is not highly


supported.
m

7. Eg:- ALOGOL, PASCAL, C, etc.

7 Compiled By Er.Shraddha Parajuli


**Top-Down Approach(Step-wise Design)**
1. Breaking down of a system to gain vision into its compositional subsystems and work on
each sub-problems separately.
2. Start with big picture and breaks down from these into smaller segments.

om
3. First focus on abstract of overall system or project and last it focuses on detailed design
or development.
4. First main function is executed and then the sub-function call which calls for code for sub

.c
function.

t
po
**Bottom-Up Approach**

systems. gs
1. Combining together various small modules / programs to give rise to more complex

2. Project implementation becomes smoother and shorter.


lo
.b

**Features of OOP**
eb

1. Inheritance / Re-usuability: The capability of a class to derive properties and


characteristics from another class is called inheritance.
2. Data hiding: Data hiding is a software development technique specifically used in
ew

object-oriented programming (OOP) to hide internal object details (data


members).
od

3. Polymorphism: polymorphism means having many forms. In simple words, we can


define polymorphism as the ability of a message to be displayed in more than one
form.
dc

4. Encapsulation: It is a process of combining data members and functions in a single


unit called class. This is to prevent the access to the data directly, the access to
m

them is provided through the functions of the class.


5. Abstraction: It 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.

**Use / Applications of OOP**


1. Can be used as a real-timed system.
2. Simulation and modeling.

8 Compiled By Er.Shraddha Parajuli


3. Object oriented database like mysql.
4. Artificial Intelligence and expert system.
5. GUI based applications like Photoshop, Premire Pro, etc
6. Web browser: a part of googles backend rendering engines of firefox etc.
7. Advanced computation and graphics: building apps like Maya3D, Image processing
apps.

om
Definition Of Class

.c
Class is defined as a user-defined data type that has its own data members and its associated

t
member functions that are accessed and used by creating class instances i.e. object.

po
gs
lo
.b
eb
ew
od
dc
m

The End

9 Compiled By Er.Shraddha Parajuli

You might also like