Skip to content

Instantly share code, notes, and snippets.

@robinp
Created July 27, 2012 08:31
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/3186839 to your computer and use it in GitHub Desktop.
Save robinp/3186839 to your computer and use it in GitHub Desktop.
bakery model using template method
abstract class Bakery1 {
public void produceBread() {
Ingredients ingredients = prepareIngredients();
Bread bread = bakeTheBread(ingredients);
if (checkQuality(bread)) {
putBreadOnDisplay(bread);
}
}
abstract Bread bakeTheBread(Ingredients ingredients);
// other methods are implemented
}
class WhiteBreadBakery1 extends Bakery1 {
@Override
Bread bakeTheBread(Ingredients ingredients) {
// magically mix ingredients into a white bread
}
}
class BioBreadBakery1 extends Bakery1 {
@Override
Bread bakeTheBread(Ingredients ingredients) {
// use more natural stuff so customers will be happy
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment