College students andCommunityVolunteers learned how to help the elderly, sweep the floor, wash clothes, and buy rice.
Package COM. WZS. design;/*** big talk design mode -- page73 factory method ** @ author administrator **/public class factorymethod {public static void main (string [] ARGs) {ifactory ifacloud = new undergraduatefactory (); // college student Lei Feng factory ifacloud. createleifeng (). buyrice (); ifacloud. createleifeng (). wash (); ifacloud. createleifeng (). sweep (); system. out. println (); ifacloud = new volunteerfactory (); // ifacloud from the volunteer Lei Feng factory. createleifeng (). buyrice (); ifacloud. createleifeng (). wash (); ifacloud. createleifeng (). sweep () ;}/ ** create Lei Feng's factory */interface ifacloud {Leifeng createleifeng ();} /** */class undergraduatefactory implements ifacloud {@ overridepublic Leifeng createleifeng () {return New Undergraduate ();}} /** volunteer Lei Feng factory */class volunteerfactory implements ifacloud {@ overridepublic Leifeng createleifeng () {return new volunteer ();}} /** Lei Feng */abstract class Leifeng {public abstract void sweep (); public abstract void wash (); public abstract void buyrice ();} /** */class undergraduate extends Leifeng {@ overridepublic void buyrice () {system. out. println ("college students buy rice for the elderly. ") ;}@ overridepublic void sweep () {system. out. println ("college students help the elderly wash clothes. ") ;}@ overridepublic void wash () {system. out. println ("college students help the elderly sweep the floor. ") ;}}/** volunteer Lei Feng */class volunteer extends Leifeng {@ overridepublic void buyrice () {system. out. println ("volunteers help the elderly buy rice. ") ;}@ overridepublic void sweep () {system. out. println ("volunteers help the elderly wash their clothes. ") ;}@ overridepublic void wash () {system. out. println ("volunteers help the elderly sweep the floor. ");}}