Objective-C Dynamic Binding and Typing with the id Type

From Techotopia
Revision as of 20:35, 27 October 2009 by Neil (Talk | contribs) (New page: So far in this series of chapters covering object oriented programming with Objective-C we have focused exclusively on static class typing and binding. In this chapter we will look at conc...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

So far in this series of chapters covering object oriented programming with Objective-C we have focused exclusively on static class typing and binding. In this chapter we will look at concepts referred to as dynamic typing and dynamic binding and how the Objective-C id type is in this context.

Static Typing vs Dynamic Typing

In previous chapters, when we have created an instance of a class we have done so by specifically declaring the type of object we are creating. For example, when we created an instance of our BankAccount class, we created a variable of type BankAccount to store the instance object:


Because we have pre-declared the type of object that is to be assigned to the account1 variable we have performed something called static typing. Having statically declared account1 as being of type BankAccount we are subsequently unable to assign an object of any other type to that variable.

Example of attempting to assign a different object type to the account1 variable here

Start to talk about dynamic typing.

Describe dynamic binding here.