Created
July 27, 2012 08:50
-
-
Save robinp/3186893 to your computer and use it in GitHub Desktop.
complex bakery model using template methods
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
abstract class PosprocessingBakery1 { | |
public void produceBread() { | |
Ingredients ingredients = prepareIngredients(); | |
Bread bread = bakeTheBread(ingredients); | |
if (checkQuality(bread)) { | |
putBreadOnDisplay(postprocess(bread)); | |
} | |
} | |
abstract Bread bakeTheBread(Ingredients ingredients); | |
abstract Bread postprocess(Bread bread); | |
// other methods are implemented | |
} | |
class WhiteSlicedBreadBakery1 extends PosprocessingBakery1 { | |
@Override | |
Bread bakeTheBread(Ingredients ingredients) { | |
// bake it | |
} | |
@Override | |
Bread postprocess(Bread bread) { | |
// slice it | |
} | |
} | |
class BioSlicedBreadBakery1 extends PosprocessingBakery1 { | |
@Override | |
Bread bakeTheBread(Ingredients ingredients) { | |
// bake it and be happy, although you are a bit worried now | |
} | |
@Override | |
Bread postprocess(Bread bread) { | |
// slice it again. you feel nervous | |
} | |
} | |
class WhiteBoxedBreadBakery1 extends PosprocessingBakery1 { | |
@Override | |
Bread bakeTheBread(Ingredients ingredients) { | |
// this isn't fun at all | |
} | |
@Override | |
Bread postprocess(Bread bread) { | |
// at least boxing is interesting | |
} | |
} | |
class BioBoxedBreadBakery1 extends PosprocessingBakery1 { | |
@Override | |
Bread bakeTheBread(Ingredients ingredients) { | |
// aaAAAARGH | |
} | |
@Override | |
Bread postprocess(Bread bread) { | |
// boxing this much sucks | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment