Last active
August 29, 2015 14:04
-
-
Save tamizhvendan/062dc9ce4593c16aaf82 to your computer and use it in GitHub Desktop.
Dynamic Polymorphism
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void btnAttack_Click(object sender, EventArgs e) | |
| { | |
| weapon.Attack(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Bomb : IWeapon | |
| { | |
| public void Attack() | |
| { | |
| System.Windows.Forms.MessageBox.Show("Bomb!!"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void rboSword_CheckedChanged(object sender, EventArgs e) | |
| { | |
| weapon = new Sword(); | |
| } | |
| private void rboGun_CheckedChanged(object sender, EventArgs e) | |
| { | |
| weapon = new Gun(); | |
| } | |
| private void rboBomb_CheckedChanged(object sender, EventArgs e) | |
| { | |
| weapon = new Bomb(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Gun : IWeapon | |
| { | |
| public void Attack() | |
| { | |
| System.Windows.Forms.MessageBox.Show("Gun!!"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IWeapon | |
| { | |
| void Attack(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public partial class MainForm : Form | |
| { | |
| private IWeapon weapon = new Sword(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Sword : IWeapon | |
| { | |
| public void Attack() | |
| { | |
| System.Windows.Forms.MessageBox.Show("Sword!!"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment