View Single Post
  #2 (permalink)  
Old January 29th, 2017, 03:46 AM
mmorgan30 mmorgan30 is offline
Friend of Wrox
Points: 528, Level: 8
Points: 528, Level: 8 Points: 528, Level: 8 Points: 528, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Default

in order to understand how this block of code:
Code:
((Button)sender).Content = "Clicked!";
is using polymorphism, you must understand what it mean. polymorphism means in general terms "many forms". meaning its values can be applied to many type.

A popular example is a car

1) a ford can be car
2) a Chevy can be a car
3) and so on....

the point is that the commonality between the examples is a the noun "car"

lets assume that we have 2 distinct types of cars 1 ford and 1 Chevy but they have similar behaviors (in this example) drive and park. well if we extract those behaviors (drive and park) to a what is known as base class or interface the we can derive "many" types of cars that have the same behavior of drive and park such Toyota and Honda without duplicating code or each.

the block of code
Code:
((Button)sender).Content = "Clicked!";
does not offer much in identifying "polymorphism" per say without the developer knowing that the "sender" object is of a "Button" "type". the block
Code:
(Button)
casts (turns it in) the "sender" into/"masks" so that the sender appears to be a "Button" object and then references its "content" property. this is a core principle of OOP. I would suggest reading up on it.
Reply With Quote