8_Objective-C Dynamic Binding

Dynamic binding is determining the method to invoke at runtime instead of at compile time. Dynamic binding is also referred to as late binding.

Note : Dynamic binding enables polymorphism.

In the following code fragment, the actual code that should be executed by the expression [anObject print_the_float_number ] is determined at runtime. The runtime system uses the selector for the method run to identify the appropriate method in whatever class of anObject turns out to be.

Simple example of dynamic binding 

As you can see in the above example, print_the_float_number method is dynamically selected in runtime.

It is an example for dynamic binding and is quite useful in many situations when dealing with similar kind of objects.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: