Created
December 23, 2010 18:42
-
-
Save kchien/753369 to your computer and use it in GitHub Desktop.
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
package demo; | |
public abstract class Homer implements EatsDonuts{ | |
public Homer() { } | |
public void eat() { | |
Donut d = getDonut(); //We want a new donut every time | |
//eat donut | |
} | |
//here is where Spring will do its magic and return a prototype | |
protected abstract Donut getDonut(); | |
// I actually prefer to do it this way, so that we don't have to make the class | |
// abstract: | |
/* | |
public Donut getDonut() { | |
return null; //if we get NPE, we know something went wrong in our xml file | |
// or we can have: | |
// return new TastyDonut(); // so that the legacy code stays the same | |
} | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment