Skip to content

Instantly share code, notes, and snippets.

@omayib
Created July 8, 2019 14:42
Show Gist options
  • Save omayib/7e9e6cce5c2fe7ca1acf13a1c86e610c to your computer and use it in GitHub Desktop.
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.
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
@herisulistiyanto
Copy link

herisulistiyanto commented Jul 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment