Chapter 1: Introduction To Object-Oriented Programming
Chapter 1: Introduction To Object-Oriented 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
OOP in Industry
object-oriented languages nowadays MS-Windows and applications in MS-Office all developed using object-oriented languages
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
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.
10
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
12
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
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
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
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 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!