[Java] 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 {@ Override public LeiFeng createLeiFeng () {return new Undergraduate ();}} /** Volunteer Lei Feng factory */class VolunteerFactory implements ifacloud {@ Override public 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 {@ Override public void buyRice () {System. out. println ("college students buy rice for the elderly. ") ;}@ Override public void sweep () {System. out. println ("college students help the elderly wash clothes. ") ;}@ Override public void wash () {System. out. println ("college students help the elderly sweep the floor. ") ;}}/** Volunteer Lei Feng */class Volunteer extends LeiFeng {@ Override public void buyRice () {System. out. println ("volunteers help the elderly buy rice. ") ;}@ Override public void sweep () {System. out. println ("volunteers help the elderly wash their clothes. ") ;}@ Override public void wash () {System. out. println ("volunteers help the elderly sweep the floor. ");}}