PersonAction.java

public interface PersonAction {
public void eat();
}

WomanEat.java

public class WomanEat implements PersonAction {
@Override
public void eat() {
Log.i("msg","woman is eating");
}
}

ManEat.java

public class ManEat implements PersonAction {
@Override
public void eat() {
Log.i("msg","man is eating");
}
}

Provider.java

public interface Provider {
public PersonAction produce();
}

WomanFactory .java

public class WomanFactory implements Provider {
@Override
public PersonAction produce() {
return new WomanEat();
}
}

ManFactory.java

public class ManFactory implements Provider {
@Override
public PersonAction produce() {
return new ManEat();
}
}

具体使用如下:

ManFactory manFactory = new ManFactory();
PersonAction action = manFactory.produce();
action.eat();