class Ship
{
function droidWillFitInCockpit() : Boolean
{
var droid:Droid = getCurrentDroid()
var droidHeight:Integer = 0;
if(this.droid.name == "C-3PO")
{
droidHeight = 167
}
elseif(this.droid.name == "r2d2")
{
droidHeight = 109
}
return (droidHeight < 130)
}
}
class Droid
{
function Droid(name:String, height:Integer)
{
this.name = name;
this.height = height;
}
}
Created
September 15, 2015 14:52
-
-
Save rymawby/da2233b58ebeae2885f4 to your computer and use it in GitHub Desktop.
Padawan to Jedi: Improve with: Tell don't ask / magic number removal / abstraction
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Much better - assuming that the ship object has been instantiated with a cockpit size / there is a setter for this .. then the droid doesn't need to care about that - nor does the ship care about the droids name or have to set the droids height.