Lecture of 24 January 1996
Homework
- 29 January
- Note that no more than a short paragraph of explanation is
necessary to answer these two questions adequately.
- Exercise 6 page 56. (Provide the requested code in either
language.)
- Exercise 7 page 56.
- 5 February
-
- Exercise 1 page 73.
- Exercise 5 page 74.
Classes and Methods (cont.)
- Object Pascal Notes
- Classes declared in
unit
s.
- All public types, instance variables, and functions
(methods) are declared
within the
interface
part of the unit.
- All private constants and variables, and the definitions of
all methods of the class are provided within the
implementation
part of the unit.
- Scope resolution mechanism is for specifying the class
to which a method belongs (
class.method
).
- Smalltalk Notes
- Browser (groups classes into categories for viewing,
creation, editing, etc.)
- Literal symbols (
#name
has value
#name
)
- Class declaration includes
- name of class
- name of superclass
- instance variable names
- class variable names
- class category (for browser)
- Method names and parameter names for methods taking
arguments are written using a keyword style
(
keyword:
)
- Assignment arrow ( <- )
- Return value specifically signalled with up-arrow ( ^ )
- Methods and instance variables can have
the same name.
- Variables are untyped.
- All instance variables are inaccessible except in class
methods.
- All methods are accessible in any method.
- Objective C Notes
- Programs may (and should) be divided by files into
interface files
(
file.h
) and implementation files
(file.m
)
- Instance variables are declared in the header files
but inaccessible outside the class methods.
-
import
is used as a unique include
mechanism.
- Class interface specifies
- name of class
- instance variables
- method prototypes
- The type
id
is used to indicate a value which is
a pointer to any arbitrary object. This follows the
untyped variable idea of Smalltalk.
- C types and object classes are distinct and do not mix!
- void is used to specify methods (and functions) returning
no value.
- Each method parameter must have a specified type
(
id
is the default type).
- Class implementations specify the bodies of the methods
noted in the class interface.
- Objects variables (variables of type
id
)
always contain a pointer to a heap-storage
object.
- C++ Notes
- Supports the interface/implementation file model.
- Class declarations provide same information
as interface in Objective-C.
- Variables and parameters can be declared to be
const
. (The word const should follow the
specification of the type to which it refers!).
- Class definitions introduce new types and variables
bound directly to objects (not pointers to objects)
can be declared.
- Member functions are simply function fields in a record
thus, one cannot give the same name to a member function
and a data member.
- Declaration of inline functions is supported.
More computing sins are committed in the
name of efficiency (without necessarily achieving it)
than for any other signle reason--including
blind stupidity. --William Wulf
- Scope resolution mechanism is for specifying the class
to which a method belongs (
class::method
).
This document is copyright 1996 by Joseph N. Wilson.