On Inheritance...

Park SungWoo (gladius@compiler.kaist.ac.kr)
Wed, 9 Apr 1997 22:58:30 +0900 (KST)

Hi.

I plan to change my implementation of OO-VRML to some extent.
This means the OO-VRML grammar will be changed more or less.
The following is my new idea which will be incorporated into my implementation
of OO-VRML. This idea is attributed mainly to Stephan Diehl's VRML++.
(Thanks, Dr. Diehl)

Before proceeding, I should apologize to working group members that
I should continue to stick to OO-VRML because it is compulsory.
My laboratory has made an official contract on developing a multi-user
VE system based on OO-VRML. However, OO-VRML grammar may change.
Yet, the name shouldn't be modified.

I found that OO-VRML supports very poorly 'inheritance' feature in OO systems.
Diehl introduced to VRML the notion of node type system and inheritance.
So I am going to add more powerful and more methodical inheritance feature
into OO-VRML implementation.

Diehl said the top class of the inheritance hierarchy is SFNode in his
VRML++. OO-VRML will adopt this strategy. Similarly to VRML++, extending
a prototype (or class) by 'extends' keyword is, I think, good and
indispensable for object-orientation.

Suppose that we want to define a prototype (or class) which represents
a robot, as shown:
(I am very sorry for writing the example in OO-VRML based syntax.)

PROTO Robot [
eventIn SFInt32 X
Field SFRotation rot 0 0 1 0
Field SFColor clr 1 1 1
] {
Transform {
rotation IS rot
children [
...
Color {
color IS clr
}
]
}
HANDLER X {
url "vrmlscript:
function main(c,t) {
// compute new 'rot' according to SFInt32 c
// rot = f(c) for some function f()
}
"
}
}

Class Robot has two fields, rot and clr.
Class Robot has an event handler X which receives an SFInt32 value c and
computes its new rotation vector from c accordingly.

1)
Now, we want to define a new prototype similar to Robot, let's call it
NewRobot. A NewRobot node has the same structure as Robot nodes. However,
its event handler X actly slightly differently to Robot's handler X.
Consider the following code :

PROTO NewRobot extends Robot [
eventIn SFInt32 X
] {
HANDLER X {
url "vrmlscript:
function main(c,t) {
// compute new 'rot' according to SFInt32 c
// rot = g(c) for some function g()
// g() != f()
}
"
}
}

Class NewRobot has two fields, rot and clr, both of which are inherited
from its super class Robot. Class NewRobot has overridden its superclass'
handler X.
Then, my question: In this proposal, prototype NewRobot declared
eventIn SFInt32 X. Is is necessary ?? To Omit it is better ??

2)
Now, we want to define a new class HatRobot which extends Robot and has its
cool hat. I think there are two approaches.
First,

PROTO HatRobot extends Robot [
Field SFVec3f size 1 1 1
] {
Transform {
translation 0 0 1
rotation IS rot
scale IS size
children [ ... ] # description of hat
}
}

In this case, HatRobot inherits all nodes defined in class Robot.
That is, the above Transform node is added to Robot. Should we specify
it explicitly or the inheritance should be done implicitly. (This is
related with SELF notion in VRML++)

Second,

PROTO HatRobot [
Field SFVec3f size 1 1 1
eventIn SFInt32 newX
] {
Transform {
children [
Robot {
clr 1 1 1
X IS newX
}
Transform {
translation 0 0 1
scale IS size
children [ ... ]
}
}
}

In this case, the hat does not rotate. This approach is poor at first glance.
But I think it is sometimes necessary. For example, how can we apply a
Transform to Robot in the definition of NewRobot ??

I am still trying to figure out better approach supporting inheritance fully.
I want more discussion on inheritance to be done.
Any comments appreciated.

Thank you.

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 Sungwoo Park, (Castle-Help Naive)
	homepage : http://compiler.kaist.ac.kr/~gladius
 	e-mail : gladius@compiler.kaist.ac.kr
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -