Skip to content

Instantly share code, notes, and snippets.

@robinp
Created July 27, 2012 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinp/3186856 to your computer and use it in GitHub Desktop.
Save robinp/3186856 to your computer and use it in GitHub Desktop.
bakery model using injection
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