Programming Languages (CSC-302 98S)
Outline of Class 36: Object-Oriented Languages; Introduction to Semantics
Held: Friday, May 1, 1998
- The picnic is tonight. I realize most of you also have other important
things to do (UC dinner, FOG fast, etc.) but I hope you'll try to stop
by for a little while (sorry, no extra credit).
- If you haven't done so already, you should read the chapters in Louden
on semantics (chapter 12).
- Any questions on assignment
reverse is in the book.
- However, bp has a built in
append so you'll need to
choose a different name for the operation. (I like
append has multiple interpretations.)
- I will not be giving an assignment on semantics. However, the topic
will be on the exam, so you should make sure to read in the book and
- In preparation for the discussion of semantics you should start to
the section on syntax and semantics from
the Revised (5) Report on the Algorithmic Language Scheme. You'll
need to read the section in Louden on denotational semantics first and
I certainly don't expect that you'll get most of the Scheme stuff.
Nonetheless, you should at least attempt to try.
- Multiple inheritance is both a useful and problematic addition to
an object-oriented language.
- If we're using superclasses to indicate "these are a set of methods
or properties objects provide" then it is often the case that we want
- Here's something that we can both draw and add. (E.g., a Vector)
- Here's something that we can compute with and print out. (E.g.,
almost any number.)
- Here's something like a tree that also permits us to iterate over
the elements it contains.
- But ...
- What if A subclasses both B and C and B and C each provide a
foo method. Which do we get when we call foo
on a member of A?
- What if A subclasses both B and C and B and C each subclass D.
When we create an element of class A do we get one or two elements
of class D?
- How many of these questions should be under programmer control?
- Can we guarantee efficient access to fields for the member functions
of B and C?
- Because there are two somewhat distinct uses of inheritance and
subclassing (reuse of procedures and fields vs. promises to implement
methods), some object-oriented languages provide different mechanisms
for the two.
- Java uses inheritance for the first and "interfaces" for the second.
- As one of the goals of object-oriented languages is protection of the
"internals" of objects, significant effort is often devoted to designing
appropriate protection systems.
- What are some of the restrictions we might worry about?
- Can other things look at this field, method, whatever?
- Can other elements of the same class look at this field, method,
- Can methods defined in a subclass look at fields, methods, etc.
of the superclass?
- Can someone add methods to a class without subclassing it?
- Can particular other classes gain access to a field, method, or
- One difficult question in design of object-oriented languages is:
"How do I support new classes including
an output method, given that the method should be provided by the
- Different languages have different solutions to these questions.
- Many provide three basic levels: public (anyone), protected (me and
my subclasses), private (only objects of the same type).
- C++ adds a
friend which specifies that a specific class or
method can look at your internals.
- Java adds a package protection which lets you group classes together
and restrict access to only those classes within the group.