p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning C# 6.0 Programming with Visual Studio 2015 (http://p2p.wrox.com/forumdisplay.php?f=798)
-   -   Chapter 08 Try it out Ch08Ex01 (http://p2p.wrox.com/showthread.php?t=99284)

maninblack December 1st, 2016 08:45 PM

Chapter 08 Try it out Ch08Ex01
 
Hello Everyone,
I am very very new in programming even I don't have any basic of any programming language. I started learning C# from this book and found this book very resourceful and discussed in deep which helps very much. I have an understanding problem on chapter 08 try it out 01.

As per author
Code:

((Button)sender).Content = "Clicked!";
makes use of polymorphism but I am not understanding how this thing uses polymorphism?

My Second understanding problem with
Code:

((Grid)((Button)sender).Parent).Children.Add(newButton);
I didn't understand this code at all.

Can anyone help me to understand these?

Thanks in advance.

mmorgan30 January 29th, 2017 03:46 AM

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.


All times are GMT -4. The time now is 11:45 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.