Class Gun
{
shootSound = "Bang"
function shoot()
{
makeNoise(shootSound)
}
}
Class PewPewGun extends Gun
{
shootSound = "Pew Pew"
}
Class PewPewLaserGun extend PewPewGun
{
shootSound = super.shootSound + " LASERS"
}
Created
September 17, 2015 20:53
-
-
Save rymawby/c20047953811151bbbf6 to your computer and use it in GitHub Desktop.
Padawan to Jedi: Improve with Decorators
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
? So here you could then do:
myCrappyGun = gun()
myCrappyGun.shoot() //Bang
myPewPew = PewPewGun(myCrappyGun)
myPewPew.shoot() //Pew Pew
myLaser = Lasers(myPewPew)
myLaser.shoot() //Pew Pew LASERS!
but still be able to call them without their new features so
myPewPew.shoot() //Pew Pew