You are on page 1of 18

Chapter 1: Introduction to ObjectOriented Programming

What is OOP?
OO programming is a new paradigm:

New way of thinking about what it means to compute, and about how we can structure information inside a computer

History (1/3)
Computer programming history

The history of computer programming is a steady move away from machine-oriented views of programming towards concepts and metaphors that more closely reflect the way in which we ourselves understand the world

History(2/3)
Programming progression
Programming has progressed through: machine code assembly language machine-independent programming languages procedures & functions objects

History(3/3)
OOP history
Started out for simulation of complex man-

machine systems, but was soon realized that it was suitable for all complex programming projects SIMULA I (1962-65) and Simula 67 (1967) were the first two object-oriented languages The Ideas Spread Alan Kay, Adele Goldberg and colleagues at Xerox PARC extend the ideas of Simula in developing Smalltalk (1970s)
Bjarne Stroustrup develops C++ (1980s) Other Object Oriented Languages appeared (Eiffel,
5

CLOS, SELF, Java)

OOP in Industry

Large projects are routinely programmed using

object-oriented languages nowadays MS-Windows and applications in MS-Office all developed using object-oriented languages

Why is OOP Popular?


A few possible reasons why OOP is popular: Hope that it will quickly and easily lead to increased productivity and increased reliability (solve the software crises) Similarity to techniques of thinking about problems in other domains Hope for easy transition from existing languages (e.g., C or Pascal)

OOP vs Procedural Programming


Global and shared data(1/9)
To make this comparison we need to first

consider the problem that both approaches help us to solve. When programming any system you are essentially dealing with data and the code that changes that data. These two fundamental aspects of programming are handled quite differently in procedural systems compared with object oriented systems, and these differences require different strategies in how we think about writing code

OOP vs Procedural Programming


Global and shared data(2/9)
Procedural programming
In procedural programing our code is organised

into small "procedures" that use and change our data. These functions typically take some input, do something, then produce some output. Ideally your functions would behave as "black boxes" where input data goes in and output data comes out. in a procedural system our functions use data they are "given" (as parameters) but also directly access any shared data they need.

OOP vs Procedural Programming


Global and shared data(3/9)

10

OOP vs Procedural Programming


Global and shared data(4/9)
Object oriented programming
In object oriented programming, the data and

related functions are bundled together into an "object". Ideally, the data inside an object can only be manipulated by calling the object's functions. This means that your data is locked away inside your objects and your functions provide the only means of doing something with that data. In a well designed object oriented system objects never access shared or global data, they are only permitted to use the data they have, or data they are given.
11

OOP vs Procedural Programming


Global and shared data(5/9)

12

OOP vs Procedural Programming


Global and shared data(6/9)
We can see that one of the principle differences is

that procedural systems make use of shared and global data, while object oriented systems lock their data privately away in objects Let's consider a scenario where you need to change a shared variable in a procedural system. Perhaps you need to rename it, change it from a string to a numeric, change it from a struct to an array, or even remove it completely.

13

OOP vs Procedural Programming


Global and shared data(7/9)
In a procedural application you would need to find

and change each place in the code where that variable is referenced. In a large system this can be a widespread and difficult change to make.

14

OOP vs Procedural Programming


Global and shared data(8/9)
In an object oriented system we know that all

variables are inside objects and that only functions within those objects can access or change those variables. When a variable needs to be changed then we only need to change the functions that access those variables. As long as we take care that the functions' input arguments and output types are not changed, then we don't need to change any other part of the system.

15

OOP vs Procedural Programming


Global and shared data(9/9)

Conclusion
The access to data in OOP is managed by specialized member functions and no by any other function could do this job so when writing, debugging or maintaining the program written in an OOP language knowa where to go .

16

OOP vs Procedural Programming


Real World modeling

OOP is more coherent with the real world: Modeling real world objects like persons or car is not so easy with procedural programming But it is evident and easy to model this objects in OOP because the concepts of behaviours and attributes are taken into consideration in OOP. It is easy to model or to represent them

17

OOP advantages
Building the system as a group of interacting

18

objects: - Allows extreme modularity between pieces of the system - May better match the way we (humans) think about the problem - Avoids recoding, increases code-reuse Classes can be arranged in a hierarchy Subclasses inherit attributes and methods from their parent classes This allows us to organize classes, and to avoid rewriting code new classes extend old classes, with little extra work!

You might also like