Created
July 8, 2019 14:42
-
-
Save omayib/7e9e6cce5c2fe7ca1acf13a1c86e610c to your computer and use it in GitHub Desktop.
the fundamental of abstract class. When are you use abstract class or use interface.
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
TheGunListener theGunListener = new TheGunListener(); | |
//shotGun is take out one projectiles per shoot | |
Gun shotGun = new ShotGun("S12K", "Brown"); | |
shotGun.addProjectile(3); | |
shotGun.setOnShootListener(theGunListener); | |
//Deagle is take out two projectiles in one shoot | |
Gun deagle = new Deagle("Deagle", "Red"); | |
deagle.addProjectile(3); | |
deagle.setOnShootListener(theGunListener); | |
Snipper snipper = new Snipper(); | |
snipper.setGun(shotGun); | |
string info1 = snipper.getGun().getType(); // S12K | |
Console.WriteLine(info1); | |
string info2 = snipper.getGun().getColor(); // Brown | |
Console.WriteLine(info2); | |
snipper.shoot(); // Completed. The projectile was 2 | |
snipper.shoot(); // Completed. The projectile was 1 | |
snipper.shoot(); // Failed. Please reload | |
Console.WriteLine("================================= next gun >>>>>"); | |
snipper.setGun(deagle); | |
string info3 = snipper.getGun().getType(); // Deagle | |
Console.WriteLine(info3); | |
string info4 = snipper.getGun().getColor(); // Red | |
Console.WriteLine(info2); | |
snipper.shoot(); // Completed. The projectile was 1 | |
snipper.shoot(); // Failed. Please reload | |
snipper.shoot(); // Failed. Please reload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Swift, https://gist.github.com/dhiyaulhaqZA/618d5b06d558b58bb7aa011508c85ec0