![Page 1: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/1.jpg)
1
COSC2767: Object-Oriented Programming
Haibin Zhu, Ph. D.
Associate Professor of CS, Nipissing University
![Page 2: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/2.jpg)
2
Contact Me Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing
University Room: A124A Ext.: 4434 Email: [email protected] URL: http://www.nipissingu.ca/faculty/haibinz Office Hour: Mon. & Tue.12:30pm-3:30pm;
or by appointment
![Page 3: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/3.jpg)
3
Course Description Covers the concepts of OOP languages and
systems fundamental abstraction, modularity and
encapsulation mechanisms in OOP Advanced OOP concepts
polymorphism and operator overloading; message passing via generic functions; late versus early binding times; and inheritance mechanisms and their relationship to the type systems of programming languages.
Templates, Design Patterns Java and Eclipses
![Page 4: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/4.jpg)
4
How to get the goals Read and remember
Read the books, remember the language Think
Think in objects, think in classes Practice
Do as many coding as possible and make them running
Ask Email me questions
![Page 5: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/5.jpg)
5
Prerequisite Basic knowledge of
Programming COSC1557, COSC1567
![Page 6: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/6.jpg)
6
The Textbooks Used Timothy A. Budd, The Introduction to
Object-Oriented Programming (3rd Edition), Addison-Wesley, 2001, ISBN 0201760312
Avinash C. Kak, Programming with Objects: A comparative presentation of object-oriented programming with C++ and Java, John Wiley & Sons, 2003. ISBN: 0-471-26852-6.
![Page 7: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/7.jpg)
7
Lecture 1
Thinking in Objects
![Page 8: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/8.jpg)
8
Contents
Methodology(Philosophy) Programming Techniques Object-Oriented Languages Object and Large Systems
![Page 9: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/9.jpg)
9
Thinking Methodology
Induction (Abstract) From specialization to generalization
From different dogs to create the word “dog”
Dog
![Page 10: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/10.jpg)
10
Thinking Methodology
Deduction(infer) From generalization to specialization
From the word “dog” you have learnt to know an animal is or not a dog.
DOG
![Page 11: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/11.jpg)
11
Design Methodologies
Functional decomposition (Top-Down) The whole system is characterized by a
single function, and then the function is decomposed into a set of functions in a process of stepwise refinement.
![Page 12: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/12.jpg)
12
Functional decomposition
The System
Function1 Function2 Function3
Function11 Function12
. . . . . .
. . . . . .
. . . . . .
Studying
Desk Table top Filing cabinet Bookshelves
Left drawer Middle drawer Right drawer
![Page 13: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/13.jpg)
13
Design Methodologies Functional composition (bottom-up)
You can have different components of functions such as that from a function library
You can compose them into a module with a more significant function.
![Page 14: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/14.jpg)
14
Functional composition
The System
Function1 Function2 Function3
Function11 Function12
. . . . . .
. . . . . .
. . . . . .
Studying
Desk Table top Filing cabinet Bookshelves
Left drawer Middle drawer Right drawer
![Page 15: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/15.jpg)
15
Functional (De)Composition
Also known as top-down development Widely deemed to be a “good thing” Regard thing to be developed as a hierarchy State top level, and decomposing into smaller
functions. Decomposition continues until code level. Modules with well-defined semantics that can be
directly implemented. Procedures owe the data Data plays a secondary role Does not necessarily reflect the states of
abstraction in the application.
![Page 16: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/16.jpg)
16
Object-Orientation
It is a kind of thinking methodology Everything in the world is an object; Any system is composed of objects (certainly
a system is also an object); The evolution and development of a system
is caused by the interactions among the objects inside or outside the system
![Page 17: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/17.jpg)
17
Everything in the world is an object
A flower, a tree, an animal A student, a professor A desk, a chair, a classroom, a building A university, a city, a country The world, the universe A subject such as CS, IS, Math, History, …
![Page 18: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/18.jpg)
18
Any system is composed of objects
A law system A cultural system An educational system An economic system An Information system A computer system
![Page 19: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/19.jpg)
19
The development of a system is caused by the interactions
Nipissing University is developed by the interactions among: students professors staffs officers of Ontario officers of Canada … ...
Inside Nipissing
Outside Nipissing
![Page 20: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/20.jpg)
20
Design Methodologies Object-Orientation is one of the
computational thinking methodologies. Object-Orientation is a kind of design
methodology(OOA/OOD) Objects are the building blocks of the
program(interface object(editor, menu, file, etc), data managing object(db), etc.).
Objects represent real-world abstractions within the application.
![Page 21: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/21.jpg)
21
Design Methodologies
Object-orientation supports both induction: objects -> a class
This needs the tools for OOA/OOD. and deduction: a class ->objects
This needs the programmers to learn about the class library.
![Page 22: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/22.jpg)
22
Design Methodologies
Object-orientation supports both Top-down:
from a superclass to subclasses; complex objects to simple objects.
Bottom-up: from subclasses to a superclass Simple objects to complex objects
![Page 23: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/23.jpg)
23
Object-Orientation “The World is Object-Oriented”
----Alan Kay said. If you know the world, you know object-
orientation. So, object-orientation is easy.
![Page 24: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/24.jpg)
24
Programming is like writing. If you can write a demonstration, you
can make a program. So, programming is also easy. Then, Object-oriented programming
equals easy + easy, that’s too(2) easy.
Programming
![Page 25: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/25.jpg)
25
Programming
But, actually, programming is not so easy, because a real good program is not easily programmed. It needs the programmers’ lots of wisdom, lots of knowledge about programming and lots of experience.
It is like writing, to be a good writer needs lots of experience and lots of knowledge about the world.
Learning and practice are necessary.
![Page 26: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/26.jpg)
26
Programming Techniques
The evolution of programming techniques is to make programming languages
more expressive to develop complex systems more
easily
![Page 27: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/27.jpg)
27
Programming Techniques
Unstructured Programming Procedural Programming Modular & Structural Programming Abstract Data Type Object-Oriented Programming
![Page 28: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/28.jpg)
28
Unstructured Programming
Usually, people start learning programming by writing small and simple programs consisting only of one main program. Here ``main program'' stands for a sequence of commands or statements which modify data which is global throughout the whole program.
Main Program
Data
![Page 29: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/29.jpg)
29
Drawbacks
This programming technique can only be used in a very small program.
For example, if the same statement sequence is needed at different locations within the program, the sequence must be copied. If an error needed to be modified, every copy needs to be modified.
This has lead to the idea to extract these sequences(procedure), name them and offering a technique to call and return from these procedures.
![Page 30: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/30.jpg)
30
Procedural Programming
With procedural programming, you are able to combine sequences of calling statements into one single place.
A procedure call is used to invoke the procedure. After the sequence is processed, flow of control proceeds right after the position where the call was made .
Main Program
Procedure
![Page 31: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/31.jpg)
31
Procedures With parameters and sub-procedures
(procedures of procedures) , programs can now be written more structured and error free.
For example, if a procedure is correct, every time it is used it produces correct results.
Consequently, in cases of errors you can narrow your search to those places which are not proven to be correct.
![Page 32: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/32.jpg)
32
Now a program can be viewed as a sequence of procedure calls.
The main program is responsible to pass data to the individual calls, the data is processed by the procedures and the resulting data is presented.
Thus, the flow of data can be illustrated as a hierarchical graph, a tree.
Procedure Program view
![Page 33: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/33.jpg)
33
Procedure Program view
Main Program
Data
Procedure1Procedure2 Procedure3
![Page 34: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/34.jpg)
34
Modular Programming Modular programming is subdividing your
program into separate subprograms such as functions and subroutines.
With modular programming, procedures of a common functionality are grouped together into separate modules.
A program therefore no longer consists of only one single part. It is now divided into several smaller parts which interact through procedure calls and which form the whole program.
![Page 35: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/35.jpg)
35
Main Program(Also a module)
Data
Data Data1
Module2
+Data Data2
Module1
+Data Data1
Procedure1Procedure2
The main program coordinates calls to procedures in separate modules and hands over appropriate data as parameters.
Procedure3
![Page 36: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/36.jpg)
36
Modular Programming
Each module can have its own data. This allows each module to manage an internal state which is modified by calls to procedures of this module.
Each module has its own special functionalities that supports the implementation of the whole program.
![Page 37: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/37.jpg)
37
Structural Programming Also structured programming A subset of procedural programming that
enforces a logical structure on the program being written to make it more efficient and easier to understand and modify.
Certain languages such as Ada, Pascal, and dBASE are designed with features that encourage or enforce a logical program
![Page 38: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/38.jpg)
38
Structural Programming
Three Types of Structures in a structured program
Statement sequence(s1,s2,…,sn)
Branch(if-then-else)
Loop(for,do, and while loops)
Keep no goto!!! Keep modules!!!
How many basic structures for programming?
![Page 39: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/39.jpg)
39
Abstract Data Types (ADTs) A set of data values and associated
operations that are precisely specified independent of any particular implementation.
Come with Modular Programming Abstraction Model Properties of Abstract Data Types Abstract Data Types and Object-Orientation
![Page 40: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/40.jpg)
40
Abstraction: Handling Problems
A process of generalization by reducing the information content of a concept or an observable phenomenon, typically in order to retain only information which is relevant for a particular purpose.
Try to understand the problem to separate necessary from unnecessary details: You try to obtain your own abstract view, or model,
of the problem. This process of modeling is called
abstraction.
![Page 41: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/41.jpg)
41
Problem Model
Abstraction
Two of the most important types of abstraction are the following: Division into parts: Has-A abstraction Division into specialization: Is-A
abstraction
![Page 42: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/42.jpg)
42
Has-A Abstraction Division into parts takes a complex system,
and divides into component parts, which can then be considered in isolation. Characterized by sentences that have the words ``has-a''
A car has-a engine, and has-a transmission A bicycle has-a wheel A window has-a menu bar Allows us to drop down a level of complexity
when we consider the component in isolation.
![Page 43: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/43.jpg)
43
Is-a Abstraction Is-a abstraction takes a complex system, and
views it as an instance of a more general abstraction. Characterized by sentences that have the words ``is-a''
A car is a wheeled vehicle, which is-a means of transportation
A bicycle is-a wheeled vehicle A pack horse is-a means of transportation Allows us to categorize artifacts and
information and make it applicable to many different situations.
![Page 44: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/44.jpg)
44
Model A model is an abstraction or conceptual
object used in the creation of a predictive formula or a solution.
A model defines an abstract view to the problem and focuses only on problem related stuff and that you try to define properties: the data which are affected; the operations which are identified;
ADT is a kind of Model.
![Page 45: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/45.jpg)
45
•Abstract data types are a partial solution to models •ADT defines the interface to a data abstraction without specifying implementation detail.
Abstract data types(ADT)
![Page 46: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/46.jpg)
46
Properties of ADT With abstraction, you create (1) a well-
defined entity which can be properly handled.
These entities define (2) the data structure of a set of items. For example, each administered employee
has a name, date of birth and social number....
![Page 47: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/47.jpg)
47
Properties of ADT(Cont’d)
The data structure can only be (3) accessed with defined operations. This set of operations is called interface and
is exported by the entity. An entity with the properties just
described is called an abstract data type (ADT).
![Page 48: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/48.jpg)
48
Interface
Operations
Abstract Data Structure
Abstract Data Type
ADT
![Page 49: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/49.jpg)
49
Definition (ADT)
ADT is characterized by the following properties: 1. It exports a type. 2. It exports a set of operations. This set is
called interface. 3. Operations of the interface are the only
access mechanism to the type's data structure.
4. Axioms and preconditions define the application domain of the type.
![Page 50: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/50.jpg)
50
Example: ADT List
Type List. The interface to instances of type List is
defined by the interface definition file. Operations: insert, get, append,
delete,search,…
![Page 51: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/51.jpg)
51
List The application domain is defined by the
semantics meaning of the provided operations. Axioms and preconditions include statements such as ``An empty list is a list.'' ``Let l=(d1, d2, d3, ..., dN) be a list. Then
l.append(dM) results in l=(d1, d2, d3, ..., dN, dM).''
``The first element of a list can only be deleted if the list is not empty.''
![Page 52: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/52.jpg)
52
Encapsulation(1)
Combine the data and the operations Enclosing of both variables and functions Keep details of the data and operations from
the users of the ADT Once you have created an ADT for complex
numbers, say Complex, you can use it in the same way like well-known data types such as integers.
![Page 53: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/53.jpg)
53
Encapsulation(2) Allows Modularity Controlled access to data Separates implementation from
interface It extends the built-in types
![Page 54: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/54.jpg)
54
Object-Oriented Programming
Object is derived from abstract data type Object-oriented programming has a web of
interacting objects, each house-keeping its own state.
Objects of a program interact by sending messages to each other.
![Page 55: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/55.jpg)
55
Object1
Data1+Procedures1
Data Data1 Object3
Data3 + Procedures3
Object2
Data2 + Procedures2
Object4
Data4 + Procedures4
![Page 56: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/56.jpg)
56
Object-Oriented Programming
In object-oriented programming , instead of calling a procedure which we must provide with the correct handle, we would directly send a message to the object in questions.
Roughly speaking, each object implements its own module.
![Page 57: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/57.jpg)
57
Object-Oriented Programming
Each object is responsible to initialize and destroy itself correctly.
Consequently, there is no longer the need to explicitly call a creation or termination procedure.
![Page 58: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/58.jpg)
58
Kay’s Description of OOP Everything is an object Objects perform computation by making requests of
each other through the passing of messages Every object has it's own memory, which consists of
other objects. Every object is an instance of a class. A class
groups similar objects. The class is the repository for behavior associated
with an object Classes are organized into singly-rooted tree
structure, called an inheritance hierarchy.
![Page 59: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/59.jpg)
59
ADT and Object-Orientation
ADTs allows the creation of instances with well-defined properties and behavior.
In object-orientation, ADTs are referred to as classes.
Therefore, a class defines properties of objects which are the instances in an object-oriented environment.
![Page 60: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/60.jpg)
60
ADT and Object-Orientation(2)
ADTs define functionality by putting main emphasis on the involved data, their structure, operations as well as axioms and preconditions.
Object-oriented programming is ``programming with ADTs'': combining functionality of different ADTs to solve a problem.
Therefore instances (objects) of ADTs (classes) are dynamically created, destroyed and used.
![Page 61: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/61.jpg)
61
ADT and Object-Orientation(3)
•ADTs still lack self-reference and conceptual locality of objects.•Data types and operations are almost objects, but need to put them together and give the result a name which can be self-referenced.
![Page 62: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/62.jpg)
62
A Formula
Object-Orientation = Object (Abstraction) + Class (ADT & Classification) + Inheritance (Reusing) + Dynamic Binding (Polymorphism,
Flexibility)
![Page 63: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/63.jpg)
63
Inheritance(Hierarchy)
Expresses commonality among objects Allows code reusability Highlights Generalization/Specialization
relationships We will learn more in the following
lectures.
![Page 64: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/64.jpg)
64
Polymorphism
The ability of objects to respond differently to the same message or function call.
We will discuss more in the following lectures.
![Page 65: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/65.jpg)
65
Modules Information hiding Data encapsulation Abstract data types Classes and Objects
Object-Orientation Evolution
![Page 66: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/66.jpg)
66
Simply Remember
Encapsulation(Data & Operations)--- A technique for Information Hiding-----the users of the objects could not see the details of the data and operations of the objects.
Data Abstraction ---- the procedure to find a class from objects.
Abstract Data Type---- Class.
![Page 67: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/67.jpg)
67
Object-Oriented Languages An object-based programming language is one
which easily supports object-orientation. Smalltalk:1972-1980, Alan Kay C++:1986, Bjarne Stroustrup Java:1992 (Smalltalk + C++), James Gosling C#:
Developed at Microsoft by Anders Hejlsberg et al, 2000 Event driven, object oriented, visual programming
language (C++ and Java) Others:
Effile, Objective-C, Ada, ...
![Page 68: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/68.jpg)
68
Programming in the Small and Programming in the Large
Programming in the Small: One programmer, understands everything from
top to bottom. Major problem is the development of algorithms.
Programming in the Large: System is developed by large team of
programmers Major problems are management of details and
communication between programmers and between their respective software subsystems.
![Page 69: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/69.jpg)
69
Programming in the Small: One programmer, understands everything from
top to bottom. Major problem is the development of algorithms.
Programming in the Large: System is developed by large team of
programmers Major problems are management of details and
communication between programmers and between their respective software subsystems.
Objects and Large Software Systems(1)
![Page 70: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/70.jpg)
70
Objects and Large Software Systems(2)
Object view Makes systems more intuitively understandable Unifies design and programming method Initial program thoughts are informal objects-and-
interactions descriptions, even when using a non-OO language.
Divides code into logical chunks individuals of a team can be experts in, and outsiders can understand via interfaces
Allows "off the shelf" code libraries to be reused Supports code evolution: internals can always be re-
written as long as interface stays the same
![Page 71: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/71.jpg)
71
Objects and Large Software Systems(3)
So, in large software system, we need more CONCEPTS and STRUCTURES of object-orientation than PROGRAMMING SKILLS
Those are OOA(Object-Oriented Analysis) and OOD(Object-Oriented Design), that will be discussed more deeply in Software engineering or Software designing methodology.
![Page 72: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/72.jpg)
72
Summary Methodology (Philosophy) Programming Techniques Object-Oriented Languages Object and Large Systems
![Page 73: 1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University](https://reader030.vdocuments.net/reader030/viewer/2022032723/56649d205503460f949f5877/html5/thumbnails/73.jpg)
73
The End
The End of Lecture 1