//一个接口
public interface Sender{
public void send();
}
//实现类-1
public class MailSender implements Sender{
@override
public void send(){
System.out.println(“This is mail”);
}
}
//实现类-2
public class SmsSender implements Sender{
@override
public void send(){
System.out.println(“This is Sms");
}
}
//工厂类
public class SendFactory{
public Sender produceMail(){
return new MailSender();
}
public Send produceSms(){
return new SmsSender();
}
}
//测试类
public class Test{
public static void main(String[] args){
SendFactory sf = new SendFactory();
Sender sender = sf.produceSms();
sender.send();//This is Sms
}
}