Skip to content

Instantly share code, notes, and snippets.

@kchien
Created December 23, 2010 18:42
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 kchien/753369 to your computer and use it in GitHub Desktop.
Save kchien/753369 to your computer and use it in GitHub Desktop.
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