OOP with Java
Hsuan-Tien Lin
Deptartment of CSIE, NTU
OOP Class, April 28, 2009
H.-T. Lin (NTU CSIE) OOP with Java OOP(even) 04/28/2009 0 / 10
One Common Suggestion
Can we BE more OOP?
Sure, but what do you want to learn?
H.-T. Lin (NTU CSIE) OOP with Java OOP(even) 04/28/2009 1 / 10
My View about the Course
How to use Java to realize OOP?
abstract OOP thinking: UML concrete OOP realization: Java
H.-T. Lin (NTU CSIE) OOP with Java OOP(even) 04/28/2009 2 / 10
But More...
How to use Java to realize OOP &
to write programs?
a modern and useful 1st language: C a modern and useful 2nd language: Java
H.-T. Lin (NTU CSIE) OOP with Java OOP(even) 04/28/2009 3 / 10
Our Past Focus: the Common Part
How to use Java to realize OOP &
to write programs?
the mechanism within a language (and the platform) almost your only chance because there is no PL class now
H.-T. Lin (NTU CSIE) OOP with Java OOP(even) 04/28/2009 4 / 10
The Missing Part, OOP-Wise
how does one design good OOP program (emphasized in recent homeworks)?
how does the mechanism relate to OOP?
Let’s go with a bigger picture.
H.-T. Lin (NTU CSIE) OOP with Java OOP(even) 04/28/2009 5 / 10
The Java Mechanism to Abstraction (1/2)
abstraction
the ability to express and manipulate objects class for blueprint (as the “class” file)
instance for individual objects (in memory)
reference (a.k.a. type-safe pointer) for the “handle” of object object lifecycle: from constructor to finalizer
H.-T. Lin (NTU CSIE) OOP with Java OOP(even) 04/28/2009 6 / 10
The Java Mechanism to Abstraction (2/2)
abstraction
the ability to express and manipulate objects data (a.k.a. memory interpretation):
important for program designers
not so important for component users (see encapsulation) action (a.k.a. method invocation): pass in this for
instance-specific actions
H.-T. Lin (NTU CSIE) OOP with Java OOP(even) 04/28/2009 7 / 10
The Java Mechanism to Composition
composition
the ability to play and interact with objects didn’t emphasize it, but naturally just used it
object accessing scheme (use existing classes through static/instance/local variables)
—again, object lifecycle
action invocation scheme (stack frame, parameter passing, and return value)
—again, instance-specific (and independent) actions
H.-T. Lin (NTU CSIE) OOP with Java OOP(even) 04/28/2009 8 / 10
The Java Mechanism to Inheritance
inheritance
the ability to extend objects type compatibility
—hierachy in a full-OO language
same reference, compatible types, how?
—possibly, shared prefix mechanism same reference, overridden actions, how?
—will talk more in polymorphism
H.-T. Lin (NTU CSIE) OOP with Java OOP(even) 04/28/2009 9 / 10
The Java Mechanism to Encapsulation
encapsulation the ability to “pack” objects as an advanced abstraction
—safer (and more clear) to be “public” only when necessary language/platform support for different access levels
H.-T. Lin (NTU CSIE) OOP with Java OOP(even) 04/28/2009 10 / 10