Created
July 27, 2012 08:37
-
-
Save robinp/3186856 to your computer and use it in GitHub Desktop.
bakery model using injection
This file contains 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
interface BakeBreadStrategy { | |
Bread bake(Ingredients ingredients); | |
} | |
class Bakery2 { | |
public Bakery2(BakeBreadStrategy bakeStrategy) { | |
// ... | |
} | |
public void produceBread() { | |
Ingredients ingredients = prepareIngredients(); | |
Bread bread = bakeStrategy.bake(ingredients); | |
if (checkQuality(bread)) { | |
putBreadOnDisplay(bread); | |
} | |
} | |
// other methods are implemented | |
} | |
class BakeWhiteBreadStrategy extends BakeBreadStrategy { | |
@Override | |
Bread bake(Ingredients ingredients) { | |
// do it | |
} | |
} | |
class BakeBioBreadStrategy extends BakeBreadStrategy { | |
@Override | |
Bread bake(Ingredients ingredients) { | |
// do it and feel the sunshine | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment