[MUD-Dev] Re: PDMud thread summary

Alex Oren alexo at bigfoot.com
Tue Oct 27 09:47:14 CET 1998


On Mon, 26 Oct 1998 23:10:52 -0700, Chris Gray wrote:

} [Alex Oren:]
} 
}  >I think we should look into the object model first.
}  >Do we want single or multiple inheritance?  Static or dynamic binding?  Single
}  >or multiple dispatch?  Vtables or name-based?  Etc...
} 
} I'll admit ignorance again. What does single or multiple dispatch apply
} to? I can guess at what you are meaning by static versus dymamic
} binding, but I suspect my interpretation won't be what you intend. So,
} could you provide brief explanations of what you mean by all this
} jargon? (Well, to me the first and last are clear enough.)

Hmmm...

[Warning: gross simplifications (and possibly minor inaccuracies) follow]

OK, let's start with the easy one.

Static binding is when the destination of a function call is known at compile
time.  Dynamic binding is when the destination is only known at run-time.  In
C++, dynamic binding is accomplished using virtual methods and pointers or
references to objects.

C++ examples:

    class Base {
    public:
        void F() { /* do something */ }
        virtual void VF() { /* do something */ }
    };

    class Derived: public Base {
    public:
        void F() { /* do something */ }
        virtual void VF() { /* do something */ }
    };

    int main() {
        Base b;
        Derived d;
        Base& ref = d;
        Base* p = &d;

        b.F();      // Static binding
        d.F();      // Static binding
        b.VF();     // Static binding
        d.VF();     // Static binding
        ref.F();    // Static binding
        ref.VF();   // Dynamic binding, Derived::VF() called
        p->F();     // Static binding
        p->VF();    // Dynamic binding, Derived::VF() called

        return 0;
    }

C++ accomplishes static binding by direct CALL commands and dynamic binding
via indirect calls through a virtual function table.

In some other OO languages (Smalltalk, Self, etc.) you can send ANY message to
ANY object.  This is much more flexible.

Now, to multiple dispatch.  Multiple dispatch is what Scott Meyers (More
Effective C++) calls "Making functions virtual with respect to more than one
object".  C++ and Java do not support this paradigm directly but there are
ways to simulate it.

Some references:
    http://www.cs.monash.edu.au/~davidc/muldisp/muldisp.html
    http://g.oswego.edu/dl/oosd/ch21.html

Have fun,
Alex.




More information about the mud-dev-archive mailing list