DOC PREVIEW
Princeton COS 217 - Object-Oriented Programming

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Copyright 1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: Object-Oriented Programming Page 263 November 30, 1997 Object-Oriented Programming • Object-oriented programming (OOP) is a methodology = abstract data types (ADTs)+ inheritance+ dynamic binding • OO programming languages (OOPLs) have features to support this methodology Simula 1967 static inheritance and dynamic bindingCLU 1980 abstract datatypesSmalltalk 1980ZetaLisp 1984 (along with other OO Lisps)C++ 1985Objective-C 1988Oberon 1988SELF 1989Modula-3 1990Oberon-2 1991and many more...Copyright 1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: C++ vs Modula-3 (A View) Page 264 November 30, 1997 C++ vs Modula-3 (A View) feature C++ Modula-3safe no yes efficient yes yes garbage collection any day nowyes static typechecking mostly yes enforced interfaces yes yes concurrency no yes widely available yes no everyone knows it so they claimno software tools yes some good for a summer job probably noCopyright 1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: A Brief History of Modula-3 Page 265 November 30, 1997 A Brief History of Modula-3 Algol-60 1960procedures, parameters, arrays,BEGIN-END, WHILE-DO, FOR-DOSimula-67 1967Algol-60 plus pointers, records, inheritancePascal 1971 Simula-67 cleaned up minus inheritanceModula 1978 Pascal plus abstract data typesModula-2 1980 Modula cleaned up plus interfacesModula-2+ 1985 Modula-2 plus concurrency and exceptionsOberon 1988 Modula-2 stripped down plus inheritanceModula-3 1990Module-2+ cleaned up plus objects, inherit-ance, and dynamic binding (influenced by Oberon)Oberon-2 1991 Oberon plus methodsCopyright 1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: Abstract Data Types Page 266 November 30, 1997 Abstract Data Types • ADTs support data abstraction hides representation detailsreduces coupling promotes reuse • Procedures help make code representation independent, e.g., interface line.h #ifndef LINE_INCLUDED#define LINE_INCLUDED#define MAX_LINE_SIZE 256typedef struct Line_T *Line_T;extern Line_T Line_New( char *text );extern char *Line_Text( Line_T line );extern void Line_Insert( Line_T current, Line_T new );extern void Line_Delete( Line_T line );extern Line_T Line_Split( Line_T line, int col );... • ADTs are a programming methodology : applicable in any language, e.g., Ceasy to preach , hard to do • ADT languages have features to support this methodologyCopyright 1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: Inheritance Page 267 November 30, 1997 Inheritance • Example: shapes in a graphics system • Interface: shape.h #ifndef SHAPE_INCLUDED#define SHAPE_INCLUDED#include "point.h"typedef enum { circle, square, triangle, ... } Kind_T;typedef struct Shape_T {Kind_T tag;Point_T center;union {float radius; /* circle */float side; /* square */...} u;} *Shape_T;extern Point_T Shape_where(Shape_T s);extern void Shape_move(Shape_T s, Point_T to);extern void Shape_draw(Shape_T s);#endifCopyright 1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: Inheritance, cont’d Page 268 November 30, 1997 Inheritance, cont’d • Implementation: shape.c #include "assert.h"#include "shape.h"#define T Shape_TPoint_T Shape_where(T s) {return s->center;}void Shape_move(T s, Point_T to) {s->center = to;Shape_draw(s);}void Shape_draw(T s) {switch (s->tag) {case circle: ...case square: ...case triangle: ......default: assert(0);}}Copyright 1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: Problems with ADTs Page 269 November 30, 1997 Problems with ADTs • Problems Shape_draw must know about all shapesnew shapes require inspecting/modifying all functions • ADTs don’t distinguish between general and specific properties e.g., between all shapes and just circles • OOPLs support this distinction ADT is a class a class inherits the fields and functions of its superclassobjects are instances of a classCopyright 1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: Using Inheritance Page 270 November 30, 1997 Using Inheritance • Revised interface: shape.h #ifndef SHAPE_INCLUDED#define SHAPE_INCLUDED#include "point.h"typedef struct Shape_T {Point_T center;} *Shape_T;typedef struct Circle_T {struct Shape_T super ;float radius;} *Circle_T;typedef struct Square_T {struct Shape_T super ;float side;} *Square_T;...#endif Note: a Circle_T is also a Shape_T , etc. Circle_T is a subtype of Shape_T , and Shape_T is a supertype of Circle_T ; ditto for Square_T • What about Shape_draw , etc?


View Full Document

Princeton COS 217 - Object-Oriented Programming

Documents in this Course
Summary

Summary

4 pages

Lecture

Lecture

4 pages

Generics

Generics

14 pages

Generics

Generics

16 pages

Lecture

Lecture

20 pages

Debugging

Debugging

35 pages

Types

Types

7 pages

Lecture

Lecture

21 pages

Assembler

Assembler

16 pages

Lecture

Lecture

20 pages

Lecture

Lecture

39 pages

Testing

Testing

44 pages

Pipeline

Pipeline

19 pages

Lecture

Lecture

6 pages

Signals

Signals

67 pages

Building

Building

17 pages

Lecture

Lecture

7 pages

Modules

Modules

12 pages

Generics

Generics

16 pages

Testing

Testing

22 pages

Signals

Signals

34 pages

Lecture

Lecture

19 pages

Load more
Download Object-Oriented Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Object-Oriented Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Object-Oriented Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?