Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CS2136: Paradigms of Computation Class 09: Object-Oriented Programming Copyright 2001, 2002, 2003, Michael J. Ciaraldi and David Finkel.

Similar presentations


Presentation on theme: "1 CS2136: Paradigms of Computation Class 09: Object-Oriented Programming Copyright 2001, 2002, 2003, Michael J. Ciaraldi and David Finkel."— Presentation transcript:

1 1 CS2136: Paradigms of Computation Class 09: Object-Oriented Programming Copyright 2001, 2002, 2003, Michael J. Ciaraldi and David Finkel

2 2 Objects: Why? zA better way to organize data and operations on it. zA better way to model: ythe real world yproblems to be solved

3 3 Objects: Why? II zBetter how? zProduce programs that are easier to: yunderstand yfix yenhance yreuse

4 4 Objects zSome Concepts yAbstraction yVirtual Machines zWhat Makes An Object yAbstraction / Encapsulation yInheritance yPolymorphism

5 5 Abstraction z“A means of achieving stepwise refinement by suppressing unnecessary details and accentuating relevant details”—Schach, Classical and Object-Oriented Software Engineering, 4 th edition, p. 189 zTo create a good abstraction, you must recognize what is important.

6 6 Abstract Machine a.k.a. Virtual Machine zIn any system, at any level, define an interface (data & actions) and hide all the details below it. zThis can be hardware, software, firmware, or any other kind of ware. zA very powerful concept, found throughout computer science (and life). yBut not always recognized!

7 7 Virtual Machine II zIf you replace a virtual machine with another one that has the same interface, the higher level should never know the difference. zOriginal meaning of computer architecture, as used in the IBM System/360 (1964).

8 8 Virtual Machine Examples zEmacs zLanguages yANSI C, Java zUnix command line yBourne Shell yBourne-Again Shell yC-shell, Tcsh yKorn Shell zUnix system calls z Java Virtual Machine z Pentium Instruction Set z UART (serial port chip) z Web server yProtocols yConfiguration files z Web browser

9 9 What is an Object? z“An instantiation of an abstract data type”— Schach and just about everyone else. zEach object is an instance of a class. yA class defines features. yEach object in that class has those features. zA class is an abstract data type which supports inheritance. zAn object is not the same as a variable which holds a reference (handle) to it.

10 10 Features of an Object zAbstraction / Encapsulation zInheritance zPolymorphism

11 11 Abstraction & Encapsulation zData and the operations which act on it are bundled together, forming a class. zDetails of the data and operations are usually hidden from outside the class. y“Data hiding” zThis is encapsulation, a way of implementing abstraction.

12 12 Inheritance z Superclass = parent class z Subclass = derived class z Each subclass inherits all attributes and methods of the superclass, but can add to or override them. z UML: Open arrow shows superclass, “is-a” relationship.

13 13 Polymorphism zA variable declared with one class can be assigned an object of that class or any subclass, but not vice-versa. zAutomatically, the correct method is dynamically bound (at runtime).

14 14 Inheritance and Polymorphism (not Object Oriented) int open(FILE *f) { determine_type(f); if (f->type == HD) open_hd(f); else if (f->type == FD) open_fd(f); else if (f->type == TAPE) open_tape(f); } z Suppose you need to implement the open() function for files on different types of storage media.

15 15 Inheritance and Polymorphism (Object-Oriented) zYou automatically get the right method at run time.

16 16 Implementing Objects zRemember how C++ was first implemented. yAs a preprocessor for the C compiler. yThe various fields and functions had funny machine-generated names.

17 17 Next Time zAn introduction / review of Java


Download ppt "1 CS2136: Paradigms of Computation Class 09: Object-Oriented Programming Copyright 2001, 2002, 2003, Michael J. Ciaraldi and David Finkel."

Similar presentations


Ads by Google