How can I explain C# interfaces and constructors to a 8 years old genius kid?
|
|
I would get them one of these toys:
And would make an analogy that the yellow piece on top has holes in it with a specific shape, and the shapes that you are allowed to pass through these holes is a concrete type of that shape. The interface, although is not creating any action on the shape, implies that the shape has to have a few characteristics, like size, how many sides, is it round, etc. As for the constructor, I'd tell them it's the "recipe" + action of building one of these little toys: (a) It's something that is specific for that type of toy; (b) it can be applied to other toys that are similar to first toy; (c) I can build it slightly different next time, like changing the color or having it's height different from the original height; etc. So after these analogies, I could point to the code (assuming you're showing code to your kid) showing the interface not interfering with the concrete class behavior, tells the class some of the features it should have, and the constructor of the class is the subroutine of building that type. Makes sense? |
|||||
|
|
You point the kid to the appropriate MSDN pages. If he's a genius, it'll suffice ;) Otherwise sit down with him, write some simple code showcasing both. The same console examples you would show a grown-up. Nothing fancy, just some lines printed in constructors to show how an object graph is created and maybe the classic animal example for the interfaces (the one with different animals implementing a Speak or Move method). If the kid is genuinely interested in programming, that will keep him entertained. If he'll lose interest after a few minutes, let him be. Have a normal childhood. Give him the "interface talk" when he'll grow up a bit. |
|||
|
|
|
|||
|
|
|||
|
|

