Monday, February 24, 2014

For my High Schooler: Inversion of Control


At dining table.

Yash: In programming class, today we have lot of discussion.

Me: About what?

Yash: Teacher was saying that Inversion of control is completely swept the programming land scape. It has changed the way, Java programs are written.  She explained Inversion of Control but most of the students were not able to understand the concept.

Me: hmm…

Yash: But you know, I know what is IoC?

Me: Explain to me.

Yash: It is very simple. In IoC, we try to separate What and When.

Me: I didn’t get it.

Yash: In a program, we have What part and When part. IoC states that separate What from When.

Me: Explain.

Yash: Let me think of an example.

Me: ok.

Yash: I saw you working on very old computer in our garage. In one of the screen, program was asking your name. You entered your name. Then it asked your address. You entered address.  In the end it asked you to save the entered value. Here What and When are tightly coupled.  You cannot enter address without entering name. This is an example of with IoC.

Me: Nice example.

Yash: It is not complete yet. It is now turn of example with IoC. Now think of today’s web page. Suppose you want to create an account with yahoo mail. This page will ask your name, address, phone number, and other things. On this page you can enter your name, address, phone number, etc. in any order.  Here What and When are separated as far as this page is concerned.

Me: Fantastic. You certainly deserve some reward. What about Ice cream.

No comments:

Post a Comment