Java的工厂模式

/////概述/////////////////////////////// //使用工厂模式后Meeting2不用修改,开会只需修改工厂MeetingDao的返回类即可。 public class MeetingDao { public static TalImp getTalkInstance(){ return new TalkInChina(); } } //////////////////////////////////////////////////////////// public class Meeting2 { public void doMeeting(TalImp talk){ talk.say(); } public static void main(String args[]){ TalImp talk=MeetingDao.getTalkInstance(); Meeting2 meeting=new Meeting2(); meeting.doMeeting(talk); } }

你可能感兴趣的:(Java的工厂模式)