CSCI-383 Object-Oriented Programming & Design Lecture 4.
-
Upload
julia-sutton -
Category
Documents
-
view
215 -
download
2
Transcript of CSCI-383 Object-Oriented Programming & Design Lecture 4.
![Page 1: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/1.jpg)
CSCI-383
Object-Oriented Programming & Design
Lecture 4
![Page 2: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/2.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
Finding the Right Level of Abstraction
A critical problem in early stages of development is to determine what details are appropriate at each level of abstraction, and (often more importantly) what details should be omitted
One does not want to ignore or throw away important information
But one does not want to manage too much information, or have the amount of information hide critical details
![Page 3: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/3.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
Finding the Right Level of Abstraction (cont’d)
A chess board problem Can a chess board,
which has 64 squares, be tiled by 32 dominoes, each covering exactly two squares?
YES In order to solve this
problem, what details do we need to keep, and what details we can ignore?
![Page 4: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/4.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
Finding the Right Level of Abstraction (cont’d)
The mutilated chess board problem If two diagonally
opposite squares are removed, can the remaining 62 squares be tiled by dominoes?
![Page 5: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/5.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
Forms of Abstraction
Abstraction is used to help understand a complex system
In a certain sense, abstraction is the imposition of structure on a system
What are the techniques that we use for handling complexity? E.g., what is a computer?
![Page 6: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/6.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
Is-a and Has-a 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 7: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/7.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
Has-a Abstraction
Most common technique people use to help understand complex systems
Division into parts takes a complex system, and divides into 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 8: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/8.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
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 Mammals are animals that have hair and nurse their
young A cat is a mammal, a dog is a mammal, …
![Page 9: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/9.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
Other Types of Abstraction -- Composition
While is-a and has-a are two important types of abstraction, there are others
Composition is one example; a form of has-a; characterized by the following Primitive forms Rules for combining old values to create new values The idea that new values can also be subject to
further combination Examples include regular expressions, type
systems, windows, lots of other complex systems
![Page 10: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/10.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
Patterns
When faced with a new problem, most people will consider successful solutions to previous problems with similar characteristics
Patterns are another attempt to document and reuse abstractions
![Page 11: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/11.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
A Short History of Abstraction Mechanisms
Another way to better understand OOP is to put it in context with the history of abstraction in computer science Assembly languages Procedures Modules ADT The Service View Objects The future....
![Page 12: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/12.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
Assembly Languages Assembly languages and linkers were perhaps the
first tools used to abstract features of the bare machine Addresses could be represented symbolically, not as
a number Symbolic names for operations Linking of names and locations performed
automatically
Abstraction allowed the programmer to concentrate more effort on defining the task to be performed and less on the steps necessary to complete the task
![Page 13: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/13.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
Procedures and Functions
Libraries of procedures and functions (such as mathematical or input/output libraries) provided the first hints of information hiding
They permit the programmer to think about operations in high level terms, concentrating on what is being done, not how it is being performed
But they are not an entirely effective mechanism of information hiding
![Page 14: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/14.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
Procedures and Functionsint datastack[100];int datatop = 0;
void init() // initialize the stack { datatop = 0; }
void push(int val) // push a value on to the stack { if (datatop < 100)
datastack [datatop++] = val; }
int pop() // pop element from the stack { if (datatop > 0)
return datastack [--datatop]; return 0; }
Where can you hide the implementation?
![Page 15: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/15.jpg)
Procedures and Functions
In the "good ol' days" of programming, data and functions coexisted on a casual basis
During the 1960s and 1970s, structured programming helped bring organization to this picture by emphasizing the use of Abstract Data Types (ADTs):
![Page 16: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/16.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
Modules
The solution to the problem of global name space congestion what the introduction of the idea of a module
A module provides the ability to divide a name space into 2 parts The public part is accessible outside the module The private part is only accessible within the module
![Page 17: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/17.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
Parnas's Principles
David Parnas described two principles for the proper use of modules: One must provide the intended user of a module with
all the information needed to use the module correctly, and with nothing more
One must provide the implementor of a module with all the information needed to complete the module, and nothing more
![Page 18: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/18.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
Modules
Solves the problem of encapsulation -- but what if your programming task requires two or more stacks?
![Page 19: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/19.jpg)
Abstract Data Type
A type is a collection of values E.g., Boolean, Integer
A data type is a type together with a collection of operations to manipulate the type E.g., Integer data type
An abstract data type (ADT) is the realization of a data type as a software component. It does not specify how the data type is implemented
![Page 20: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/20.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
Abstract Data Types An Abstract Data Type is a programmer-defined
data type that can be manipulated in a manner similar to system-provided data types Must have the ability to instantiate many different
copies of the data type Data type can be manipulated using provided
operations, without knowledge of internal representation
But ADTs were important not because they were data structures, but because they provided an easily characterized service to the rest of an application
![Page 21: CSCI-383 Object-Oriented Programming & Design Lecture 4.](https://reader030.fdocuments.us/reader030/viewer/2022032804/56649e3f5503460f94b3066b/html5/thumbnails/21.jpg)
Adapted From: An Introduction to Object Oriented Programming, 3rd Edition, by Timothy Budd
What Does the Future Hold
What will be the next evolutionary step in software? Prediction is hard, particularly about the future However, one you have accepted the idea of an
application formed from interacting agents, there is no reason why those components must exist on the same computer (distributed computing) or be written in the same language (components)
So some of the trends we see today in software are natural results of the OOP mind set