>> Now, regarding Polymorphism and Dynamic Binding.
Let me first say that if you are getting all your theoretical knowledge
from Wiki, you need to look elsewhere.
Secondly, I think you are confusing Dynamic Linking with Dynamic
Binding. Linking and Binding are completely different.
What you are talking about only loosely fits the definition of
dynamic binding
in so much as it fits a text book definition.
Really what you have is statically typed dynamic binding
where all possible functions are defined in the base class
and the compiler determines static linking of of all functions based
on the object created.
Firstly, let me guess that you are still in High-School.
1. Yes I am :)
2. You did not even comment on the Java Quake engine.
Just ignored it.
There is no
such thing as static dynamic binding. This is an example of a
contradiction.
It is a simple way of stating it even though it sounds contradictory
See...
http://burks.bton.ac.uk/burks/pcinfo/progdocs/oofaq/s23.htm
What I refer to as dynamic binding doesn't loosely fit the definition,
it is the definition.
With true dynamic binding any object can be passed any message even if it
can not respond to it.
Again you are incorrect, and show that you are ignorant of theory. I'm
being frank here because your treating me like an idiot.
Im not sure why you a making such a big deal about this.
I have said that I agree with you all these languages fit the text
book OOP definition of dynamic binding.
I will simply argue that actual full dynamic binding
is a function of a languages particular runtime system.
You can do things in small talk, Obj C, JS etc that you just can not
to in languages with where the method calls are fixed at link time.
Any time you have language which incorporates complete polymorphism, and
allows the use of pointers, you will be able to send a message to an object
that it may not understand (I.e direct the object to invoke a method which
it, nor its parent classes have implemented).
Both in Java and in REALBasic this is not possible since first, there
are no pointers, and second, because there exists an Object class from which
all objects are descended. All objects in both Java and in REALBasic,
therefore, are necessarily related.
agree
However, this is not the case for Objective C. All objects are not
necessarily related. For example, consider GNU Step Objective C. In
general, objects descend from NSObject. However, it is possible for one to
create one's own Object super class, and have objects inherit from it.
Furthermore, you can use all these objects (regardless of whether or not
they are related), in the same program.
agree
So when I declare:
id anyObjectPtr; (equivalent RB syntax is: dim anyObjectPtr as id)
It is very possible to send an object a message it can't understand.
id is an object pointer data-type in Objective C. However, since all
objects are not necessarily related it is impossible to map any interface to
an object pointed to by an id variable.
However, since in REALBasic and in Java there are no pointers, and all
objects are necessarily related, it is always possible to map some interface
to any object. Therefore, it possible for the compiler to know whether or
not an object can understand a given message.
This, Chris, I believe, is the source of your misunderstanding. Just
because the compiler can map an interface to an object, doesn't mean that
the compiler can map an implementation of the interface to the object.
The compiler can determine whether or not the object can understand the
message, but can not determine the behavior, (the meaning of the message),
for the object once it has received the message. This is an example of
Polymorphism. Sending messages to objects without knowing how they will
behave in response to a given message at compile time.
Dynamic binding simply refers to the binding of an implementation to an
interface, not the binding of an interface to an object. Therefore if I
have:
dim myLifeForm as LifeForm
//assigns some random subclass of Lifeform to myLifeForm
myLifeForm = createRandomLifeForm()
myLifeForm.die() //calls some sort of die.
This is dynamic binding. While the compiler "knows" that myLifeForm can
understand the "die" message (because the compiler "knows" that myLifeForm
has the LifeForm interface), it does not know what "die" message means for
that particular sub-class. The meaning of the "die" message is only
available once the implementation has been bound to the interface. Since
this binding, for the given example, may only occur at runtime, this is an
example of Dynamic Binding.
Now, before you start harping on me saying "Well, C++ uses pointers and
I can't send an object a message it can't understand, so your wrong." Let
me say, that you can indeed send a message to an object which it can't
understand in C++. You just have to know how to do it.
For example, declare an integer, use it as a pointer, point it to some
object, then send that object some message it can't understand. Voila.
Do you mean like this?
class a{
public:
void foo();
void bar();
};
class b{
public:
int y;
void foo2(){
y = 100;
};
};
int main (int argc, char * const argv[]) {
a my_a;
int x = &my_a;
( (b*) (x) )->foo2();
return 0;
}
My thoughts if this is what you mean.
1. Memory corruption is bad.
2. You still need to type caste the Ptr to get it by the compiler.
3. You succeed on calling a function on a object that can not support it.
So is this at all useful?
--
Email: chrisd at plaidworld dot com
iChat / AIM: crackbunny at mac dot com
Buy Art : http://www.starbounce.com
Play Games: Plaid World Studios http://www.plaidworld.com
Day job: Software Engineer for http://www.riskwise.com, Part of LexisNexis
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|