tailieunhanh - Lecture Programming languages (2/e): Chapter 13a - Tucker, Noonan

Chapter 13 - Object-oriented programming. In this chapter we present the object-oriented programming paradigm, including its history and impact, its design issues, and examples of its use. We first desctibe the idea of abstract data types, an idea that predated and greatly influenced the idea of object-miented programming. Next, we describe the object-oriented paradigm as an extension of data abstraction. | Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised that ancient and Modern writers have not attributed greater importance to the laws of inheritance . Alexis de Tocqueville Contents Prelude: Abstract Data Types The Object Model Smalltalk Java Python Ask not what you can do for your classes, Ask what your classes can do for you. Owen Astrachan Prelude: Abstract Data Types Imperative programming paradigm Algorithms + Data Structures = Programs [Wirth] Produce a program by functional decomposition Start with function to be computed Systematically decompose function into more primitive functions Stop when all functions map to program statements Procedural Abstraction Concerned mainly with interface Function What it computes Ignore details of how Example: sort(list, length); Data Abstraction Or: abstract data types Extend procedural abstraction to include data Example: type float Extend imperative notion of type by: Providing encapsulation of data/functions Example: stack of int's Separation of interface from implementation Defn: Encapsulation is a mechanism which allows logically related constants, types, variables, methods, and so on, to be grouped into a new entity. Examples: Procedures Packages Classes A Simple Stack in C Figure A Stack Type in C Figure Implementation of Stack Type in C Figure Goal of Data Abstraction Package Data type Functions Into a module so that functions provide: public interface defines type generic type element is private; package stack_pck is type stack is private; procedure push (in out s : stack; i : element); procedure pop (in out s : stack) return element; procedure isempty(in s : stack) return boolean; procedure top(in s : stack) return element; private type node; type stack is access node; type node is record val : element; next : stack; end record; end stack_pck; package body stack_pck is procedure push (in out s : stack; i : . | Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised that ancient and Modern writers have not attributed greater importance to the laws of inheritance . Alexis de Tocqueville Contents Prelude: Abstract Data Types The Object Model Smalltalk Java Python Ask not what you can do for your classes, Ask what your classes can do for you. Owen Astrachan Prelude: Abstract Data Types Imperative programming paradigm Algorithms + Data Structures = Programs [Wirth] Produce a program by functional decomposition Start with function to be computed Systematically decompose function into more primitive functions Stop when all functions map to program statements Procedural Abstraction Concerned mainly with interface Function What it computes Ignore details of how Example: sort(list, length); Data Abstraction Or: abstract data types Extend procedural abstraction to include data Example: type float Extend imperative notion