2009年2月9日 星期一

dynamic and late binding

you don't have to know the object is class People before calling People's speak method,
the object will find speak method automatically

ex:
Shape *a = [Circle new];
[a draw];
note: Circle's draw method is called

In java, you have to change object's type to People to call People's method
ex:
Shape a = new Circle();
a.draw();  // Shape's draw method is called
(Circle)a.draw();   // Circle's draw method is called

沒有留言:

張貼留言