An Overview of the Main Course Themes

Steven J Zeil

Last modified: August 20, 2013

1. OO in Programming and Design

1.1 Observations on Pre-OO Programming Languages

The Roots of OOP

1.2 Tension in Pre-OO Programming Languages

The history of programming languages and of design can be viewed as a continual contest against increasing complexity of software systems:

Problem: too many … Response Useful?
… statements nesting ( { … } ) OK
gather statements into functions OK
… functions nesting inadequate
gather functions into subsystems / “modules” Too loosely defined
gather functions into encapsulated ADTs Good
… ADTs Gather into namespaces/packages Not much help
Organize loosely into inheritance hierarchies The OO approach

1.3 Pre-OO Design Techniques

Observations on Pre-OO Design Techniques

Stepwise Refinement & Top-Down Design

Stepwise Refinement Example

Automating book handling in a library:

Stepwise Refinement Example II

They would reason that this function must both update the electronic card catalog so that the book can be found, and must also record that the book is present in the inventory of a particular branch:

function addBook (book, branchName)
{
  bookInfo = getBookInfo(book);
  record branchName as location in bookInfo;
  addToCardCatalog (bookInfo);
  addToInventory (bookInfo, branchName);
}

Stepwise Refinement Example III

Next the designers would pick one of those rather vaguely understood lines of code in that function body and expand it, either in place or as a separate function. For example:

function addBook (book, branchName)
{
  bookInfo = getBookInfo(book);
  record branchName as location in bookInfo;
  // addToCardCatalog (bookInfo)
  add to AuthorIndex (bookInfo);
  add to SubjectIndex (bookInfo);
  add to TitleIndex (bookInfo);
  cardCatalog.addToAuthorIndex
  addToInventory (bookInfo, branchName);
}

Then, again, we would pick a vaguely understood line and expand it.

Stepwise Refinement Example IV

function addBook (book, branchName)
{
  bookInfo = getBookInfo(book);
  record branchName as location in bookInfo;
  // addToCardCatalog (bookInfo)
  //   add to AuthorIndex (bookInfo);
  authorList = bookInfo.getAuthors();
  for each author au in authorList {
    catalog.authorIndex.addByAuthor (au, bookInfo);
  }
  add to SubjectIndex (bookInfo);
  add to TitleIndex (bookInfo);
  cardCatalog.addToAuthorIndex
  addToInventory (bookInfo, branchName);
}

Top-Down Example: Observations

2. The Object-Oriented Philosophy

2.1 ## Program == Simulation

The Object-Oriented Philosophy

Design from the World

Real-World Relationships

Organizing the World

OO designers would start by organizing these things into ADTs, e.g.:

Simulate the World’s Actions

Only then would OO designers consider the specific steps required to add a book to inventory:

(update the electronic card catalog so that the book can be found, and record that the book is present in the inventory of a particular branch:

Simulate the World’s Actions

function Librarian::acquisition (Book book) 
{ 
  BranchLibrary branch = this.assignment;
  Catalog catalog = mainLibrary.catalog;
  catalog.add (book, branch);
  branch.addToInventiory (book);
}

function Catalog::add (Book book)
{
  authorIndex.add (book);
  titleIndex.add (book);
  subjectIndex.add (book);
}      

OO Approach - Observations

Technically, does the same thing as the earlier design,but

2.2 Simulation == Modeling

OO Analysis & Design

Models

We can rephrase that as

Steps in Modeling

3. Putting the “Programming” in OOP

OOP in Programming Language History

Language Concepts Examples Design Concepts
Statements Stepwise Refinement
Functions FORTRAN (1957), COBOL, ALGOL, Basic (1963), C (1969), Pascal (1972) Top-Down Design
Encapsulated modules, classes Modula, Modula 2 (1970), Ada (1983) Information hiding, ADTs
Inheritance, subtyping, dynamic binding (OOP) Smalltalk (1980), C++ (1985), Java (1995) Object-Oriented A&D

3.1 What is an Object?

Maybe you thought I was never going to get around to this?

Objects

An object is characterized by

Identity

Identity is the property of an object that distinguishes it from all others. We commonly denote identity by

State

The state of an object consists of the properties of the object, and the current values of those properties.

For example, given this list of properties:

 struct Book {
    string title;
    Author author;
    ISBN isbn;
    int edition;
    int year;
    Publisher publisher;
 };

we might describe the state of a particular book as

 Book cs330Text = {
    "Object Oriented Design & Patterns", horstmann,
    "0-471-74487-5", 2, 2006,
    wileyBooks};

Behavior

Behavior is how an object acts and reacts to operations on it, in terms of

3.2 Messages & Methods

In OOP, behavior is often described in terms of messages and methods.

A message to an object is a request for service.

A method is the internal means by which the object responds to that request.

Differing Behavior

Different objects may respond to the same message via different methods.

Example: suppose I send a message “send flowers to my grandmother” to …

3.3 What is a Class?

A class is a named collection of potential objects.

In the languages we will study,

Are Objects and Classes New

OOPL Traditional PL
object variable, constant
identity label, name, address
state value
class type (almost)
message function decl
method function body
passing a message function call

Classes versus Types

Although “class” and “type” mean nearly the same thing, they do carry a slightly different idiomatic meaning.

Instances of Multiple Types

Inheritance Example

What makes a PL an OOPL

.