Title: Objects
1Objects
- Lecture OO04
- Representing Objects
2References
- Ambler, S., The Object Primer, Cambridge Univ.
Press, 2001, Chapter 1 2, Sections 5.1 - 5.5
3Teaching Points
- Review of program memory organization
- Introduction to object constructors
- Investigation of object characteristics
- Singleton Pattern
4Review
- Vehicle example?
- Memory storage types
5Collaboration Diagrams (Objects)
- A type of Interaction Diagram
- Objects
- name
- type
6Object Characteristics
7State
- where in memory do objects go
- different constructor invocations
- destructor invocations
8Memory storage types
- Static Memory
- global variables
- static class members
- static function variables
- Automatic Memory (Stack)
- local variables
- function parameters
- Free Store (Heap)
- memory explicitly requested by programmer
9class ExampleClass int i //prim. type
variable stored with the //ExampleClass object
in heap AnotherClass handleName //handle
stored with ExampleClass object //note no
object exists AnotherClass yet static int
j //primitive type var. in static
memory //note one copy used for the whole
class static AnotherClass anotherName //handle
is stored in static mem //note no object
exists yet static anotherName new
AnotherClass() //new object is stored on the
heap //all instances use this single object
public ExampleClass handleName new
AnotherClass() //new object is stored on the
heap //each instance creates its own object
public someFunction() int i //prim.
type variable stored on the stack AnotherClass
someName new AnotherClass() //where??
10Behavior
- Objects accept messages
- Message can be function calls
- Modifier
- Selector
- Iterator
- Constructor
- Destructor
11Identity
- That property that distinguishes an object from
all other objects - mixing addressing w/ identity
- mixing data value with identity
12Discussion
- What about assignment?
- What about parameter passing?
- What about equivalence?
- What about garbage collection?
13Singleton Pattern
- Print Spooler
- Network Services object
- File System
14Teaching Points
- Review of program memory organization
- Introduction to object constructors
- Investigation of object characteristics
- Singleton Pattern