Held Thursday, September 2, 1999
Today, we will consider object-oriented design by discussing the
design of the classes and objects in a particular problem.
- We will also consider possible projects.
- Discussion of object-oriented programming
- Objects and classes
- Example object-oriented designs
- Project discussion
- In order to successfully work in an object-oriented paradigm
(and an object-oriented language), you need to become accustomed
to thinking in objects.
- This is in contrast to the thinking in functions that
you did last semester.
- What is an object?
- Essentially, a collection of information and methods (functions).
- You can think of the information as giving a state to the
- In a watch, part of the state is the time that it represents.
- In a drawer, part of the state is the position of the drawer.
(We also care whether it's full or empty.)
- As you may know, object-oriented design has become one of the most
important design trends in the mid-to-late 1990's. Why?
- Object-oriented design makes it easier to encapsulate
parts of the program.
- Someone working on one object or class need only know about the
capabilities of another object, and not its internals.
- Using information hiding it becomes possible to modify
the inside of one class without affecting the operation of the
program as a whole.
- Object-oriented design can be appropriate for modelling ``real''
problems, particularly simulations.
- Object-oriented design can better support code reuse through
inheritance and polymorphism.
- We'll return to these concepts later.
- To successfully engage in object-oriented design, you need to be
able to identify the key objects and classes in your program.
- You also need to think about how they communicate.
- In lab O1, you considered
some techniques for thinking about objects.
- Write narratives.
- Circle nouns. These are potential objects.
- Box verbs. These are potential methods.
- When writing narratives, you may also want to consider what's going
on ``behind the scenes'' as it were.
- As an example, we'll work together to consider the objects one
might use in an elevator simulation (or even the software to
control that elevator).
- Assume there are N elevators and M floors.
- This is a fairly traditional first exercise in object-oriented
design. Surpringly, different books come up with very different
solutions. I'll try not to bias the results.
- We'll tell some stories:
- From the rider's perspective
- From the elevator's perspective
- From other perspectives
- We'll identify objects
- We'll consider capabilities
- We'll talk about the interactions of methods in the objects.