Thursday, June 18, 2009

Dynamic Binding And Runtime Type Interrogation

                    The combination of the last two mechanisms mentioned, redefinition and polymorphism immediately suggests the next one. Assume a call whose target is a polymorphic entity.For example,a call to the feature turn on an entity declared of type BOAT. The various descendants of BOAT may have redefined the feature in various ways. Clearly there must be an automatic mechanism to guarantee that the version of turn will always be the one deduced from the actual object’s type regardless of how the entity has been declared. This property is called dynamic binding.


                 Calling a feature on an entity should always trigger the feature corresponding to the type of the attached run time object which is not necessarily the same in different executions of the call.Dynamic binding has a major influence on the structure of object oriented applications as it enables developers to write simple calls to denote what is actually several possible calls depending on the corresponding run time situations.This avoids the need for many of the repeated tests  which plague software written with more conventional approaches.

 
                    Object oriented software developers soon develop a healthy hatred for any style of computation based on explicit choices between various types for an object. Polymorphism and dynamic binding provide a much preferable alternative. In some cases however an object comes from the outside so that the software author has no way to predict its type with certainty.This occurs in particular if the object is retrieved from external storage received from a network transmission or passed by some other system.

                  The software then needs a mechanism to access the object in a safe way, without violating the constraints of static typing. Such a mechanism should be designed with care so as not to cancel the benefits of polymorphism and dynamic binding.The assignment attempt operation described in this book satisfies these requirements. An assignment attempt is a conditional operation.It tries to attach an object to an entity if in a given execution the object’s type conforms to the type declared for the entity the effect is that of a normal assignment.Otherwise the entity gets a special “void” value. So you can handle objects whose type you do not know for sure without violating the safety of the type system.

No comments:

Post a Comment