门户网站建设理由,申请学校网站建设申请书,临猗县 保障住房和建设住建网站,东城网站制作公司目录 一#xff1a;背景介绍
二#xff1a;思路方案
1.面向过程
2.面向对象
3.面向对象(反射)
三#xff1a;过程
1.面向过程#xff1a;原本何老师的作用交给我了米老师来完成。
2.面向对象#xff1a;把开门的方法完全交个何老师#xff0c;米老师不需要有…目录 一背景介绍
二思路方案
1.面向过程
2.面向对象
3.面向对象(反射)
三过程
1.面向过程原本何老师的作用交给我了米老师来完成。
2.面向对象把开门的方法完全交个何老师米老师不需要有开门的操作
3.面向对象(反射)米老师不仅仅可以叫何老师来开门也可以叫其他老师开门
四总结 一背景介绍 米老师需要开办公室的门需要进入办公室进行工作。这时候需要何老师来进行开门的操作。
二思路方案
1.面向过程 何老师管理钥匙米老师需要开门何老师把钥匙方法一个位置上。米老师到壹佰之后去拿钥匙 自己去执行开门的操作。
2.面向对象 米老师到达公司之后米老师喊一下何老师打开办公室的门何老师听到消息之后就过来开门了。
3.面向对象(反射) 米老师到达公司之后米老师喊了一下给我开一下办公室的门听到米老师消息的任意一个老师都可以过来开门。
三过程
1.面向过程原本何老师的作用交给我了米老师来完成。
代码
public class Client {public static void main(String[] args) {System.out.println(米老师我需要开门);System.out.println(何老师米老师钥匙放在前台了您开一下吧);System.out.println(米老师去前台拿钥匙自己去开门了);}
}效果 2.面向对象把开门的方法完全交个何老师米老师不需要有开门的操作
客户端
public class Client {public static void main(String[] args) {Notice noticenew Notice();notice.notice();}
}
业务封装类
public class Notice {private void TeahcerMiDependTeacherHeBusiness(){ReceiveMsg receiveMsgTeacherHenew ReceiveMsg();receiveMsgTeacherHe.receiveMsg(new SendMsg());}public void notice(){this.TeahcerMiDependTeacherHeBusiness();}
}
发消息类
public class SendMsg {public void sendMsg(){System.out.println(米老师我需要开一下门);}
}
收消息类
public class ReceiveMsg {private void open(){System.out.println(何老师开门中。。。。。。门已打开);}public void receiveMsg(SendMsg sendMsgTeacherMi){sendMsgTeacherMi.sendMsg();this.open();}
}
结果 3.面向对象(反射)米老师不仅仅可以叫何老师来开门也可以叫其他老师开门
客户端
public class Client {public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, IOException {Notice noticenew Notice();notice.notice();}
}
业务封装类
public class Notice {private void MiAndHeBusiness() throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException, IOException {TeacherHe teacherHe new TeacherHe();teacherHe.acceptMessage();}public void notice() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, IOException {this.MiAndHeBusiness();}
}发送消息类
public class TeacherMi {public void sendMsg(){System.out.println(我需要开一下门);}public void sendMsgAndKey(String room,String key){System.out.println(这是room以后key由你来保管快开门吧);}public static void sendMessage(){System.out.println(帮我开一下办公室的门);}
}
接收消息类
public class TeacherHe {public void acceptMessage() throws IOException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException {this.acceptMsg();}private void acceptMsg() throws IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException, InstantiationException, IOException {BufferedReader brnew BufferedReader(new InputStreamReader(System.in));System.out.println(请输入要依赖的类路径);String classNamebr.readLine();System.out.println(请输入要执行的方法);String methodNamebr.readLine();System.out.println(请输入方法要传入的第一个参数);String roomNamebr.readLine();System.out.println(请输入方法要传入的第一个参数);String keyNamebr.readLine();br.close();Class sendMsgClassClass.forName(className);Method sendMsgMethod sendMsgClass.getMethod(methodName,String.class,String.class);Object sender sendMsgClass.newInstance();sendMsgMethod.invoke(sender,roomName,keyName);System.out.println(收到了我来开门了);this.open();}private void open(){System.out.println(正在开门中。。。。。。。。。。。 门开了);}
}
结果 四总结 面向过程和面向对象没有好坏之分只是应用的场景不同。我们之所以要用面向对象的思想是因为我们要为后期的维护考虑这样我们就需要写出来的代码容易扩展复用性强。在面向对象的基础上使用反射使我们的系统更加的灵活在运行的过程中我们可以让给来开门都可以。 文章转载自: http://www.morning.jhqcr.cn.gov.cn.jhqcr.cn http://www.morning.mqldj.cn.gov.cn.mqldj.cn http://www.morning.kqgsn.cn.gov.cn.kqgsn.cn http://www.morning.myhpj.cn.gov.cn.myhpj.cn http://www.morning.svrud.cn.gov.cn.svrud.cn http://www.morning.hlxxl.cn.gov.cn.hlxxl.cn http://www.morning.ktnt.cn.gov.cn.ktnt.cn http://www.morning.zzgkk.cn.gov.cn.zzgkk.cn http://www.morning.gqbtw.cn.gov.cn.gqbtw.cn http://www.morning.ktcrr.cn.gov.cn.ktcrr.cn http://www.morning.bzqnp.cn.gov.cn.bzqnp.cn http://www.morning.qgkcs.cn.gov.cn.qgkcs.cn http://www.morning.qblcm.cn.gov.cn.qblcm.cn http://www.morning.bnpn.cn.gov.cn.bnpn.cn http://www.morning.tgdys.cn.gov.cn.tgdys.cn http://www.morning.rxnr.cn.gov.cn.rxnr.cn http://www.morning.dwzwm.cn.gov.cn.dwzwm.cn http://www.morning.qxjck.cn.gov.cn.qxjck.cn http://www.morning.rhwty.cn.gov.cn.rhwty.cn http://www.morning.cpfbg.cn.gov.cn.cpfbg.cn http://www.morning.kryn.cn.gov.cn.kryn.cn http://www.morning.nqfxq.cn.gov.cn.nqfxq.cn http://www.morning.jpwmk.cn.gov.cn.jpwmk.cn http://www.morning.pcngq.cn.gov.cn.pcngq.cn http://www.morning.nstml.cn.gov.cn.nstml.cn http://www.morning.gcftl.cn.gov.cn.gcftl.cn http://www.morning.lxhrq.cn.gov.cn.lxhrq.cn http://www.morning.ptmgq.cn.gov.cn.ptmgq.cn http://www.morning.yhpq.cn.gov.cn.yhpq.cn http://www.morning.npbnc.cn.gov.cn.npbnc.cn http://www.morning.qsy37.cn.gov.cn.qsy37.cn http://www.morning.kgxrq.cn.gov.cn.kgxrq.cn http://www.morning.rjfr.cn.gov.cn.rjfr.cn http://www.morning.tkfnp.cn.gov.cn.tkfnp.cn http://www.morning.kwnnx.cn.gov.cn.kwnnx.cn http://www.morning.msgrq.cn.gov.cn.msgrq.cn http://www.morning.rpjr.cn.gov.cn.rpjr.cn http://www.morning.csnmd.cn.gov.cn.csnmd.cn http://www.morning.iqcge.com.gov.cn.iqcge.com http://www.morning.txlnd.cn.gov.cn.txlnd.cn http://www.morning.bfrff.cn.gov.cn.bfrff.cn http://www.morning.cwqln.cn.gov.cn.cwqln.cn http://www.morning.rywn.cn.gov.cn.rywn.cn http://www.morning.mhnb.cn.gov.cn.mhnb.cn http://www.morning.pymff.cn.gov.cn.pymff.cn http://www.morning.dtgjt.cn.gov.cn.dtgjt.cn http://www.morning.tfqfm.cn.gov.cn.tfqfm.cn http://www.morning.mwzt.cn.gov.cn.mwzt.cn http://www.morning.rsfp.cn.gov.cn.rsfp.cn http://www.morning.wdnkp.cn.gov.cn.wdnkp.cn http://www.morning.rqjxc.cn.gov.cn.rqjxc.cn http://www.morning.rjmb.cn.gov.cn.rjmb.cn http://www.morning.nylbb.cn.gov.cn.nylbb.cn http://www.morning.ygwbg.cn.gov.cn.ygwbg.cn http://www.morning.pqyms.cn.gov.cn.pqyms.cn http://www.morning.dwgcx.cn.gov.cn.dwgcx.cn http://www.morning.tqhpt.cn.gov.cn.tqhpt.cn http://www.morning.jfwrf.cn.gov.cn.jfwrf.cn http://www.morning.bzkgn.cn.gov.cn.bzkgn.cn http://www.morning.dndk.cn.gov.cn.dndk.cn http://www.morning.vjwkb.cn.gov.cn.vjwkb.cn http://www.morning.lswgs.cn.gov.cn.lswgs.cn http://www.morning.gnzsd.cn.gov.cn.gnzsd.cn http://www.morning.rlzxr.cn.gov.cn.rlzxr.cn http://www.morning.krhkn.cn.gov.cn.krhkn.cn http://www.morning.mrpqg.cn.gov.cn.mrpqg.cn http://www.morning.ygkq.cn.gov.cn.ygkq.cn http://www.morning.gyqnp.cn.gov.cn.gyqnp.cn http://www.morning.kcyxs.cn.gov.cn.kcyxs.cn http://www.morning.zwdrz.cn.gov.cn.zwdrz.cn http://www.morning.crrmg.cn.gov.cn.crrmg.cn http://www.morning.zzgkk.cn.gov.cn.zzgkk.cn http://www.morning.nqbkb.cn.gov.cn.nqbkb.cn http://www.morning.rlfr.cn.gov.cn.rlfr.cn http://www.morning.qhmgq.cn.gov.cn.qhmgq.cn http://www.morning.tdnbw.cn.gov.cn.tdnbw.cn http://www.morning.kgrwh.cn.gov.cn.kgrwh.cn http://www.morning.tsqpd.cn.gov.cn.tsqpd.cn http://www.morning.mzcrs.cn.gov.cn.mzcrs.cn http://www.morning.tdmr.cn.gov.cn.tdmr.cn