基于反向控制来实现MovieList调用MovieFinder的功能,具体要求:1) 基于传统的面向对象的方法来实现电影的查找和显示。2) 使用反向控制中的构造函数法来实现电影的查找和显示。3) 使用反向控制中的get/set函数法来实现电影的查找和显示。回答问题:1)与2),3)的区别是什么?为什么需要反向控制?部分代码:public interface MovieFinder { List findAll(); } public class MovieLister { private MovieFinder finder; public Movie[] moviesDirectedBy(String arg) { List allMovies = finder.findAll(); for (Iterator it = allMovies.iterator();it.hasNext();) { Movie movie = (Movie) it.next(); if (!movie.getDirector().equals(arg)) it.remove(); } return (Movie[]) allMovies.toArray(new Movie[allMovies.size()]); } public MovieLister() { finder = new MySpecialMovieFinderImplem(); }基于IOR,客户端调用服务端,获得当前时间(Time Service),具体要求:1) 使用面向对象的方法来完成此功能。2) 使用IDL描述接口,编译,客户端获得服务端对象IOR,调用并获得时间。回答问题:1)与2)的区别,2)的优势是什么?//TestTimeServer.idl module TestTimeServer{interface ObjTimeServer{ string getTime(); };};//Time Service Component ://TestTimeServerImpl.javaimport CORBA.*;class ObjTestTimeServerImplextends TestTimeServer.ObjTimeServer_Skeleton//which is generated from IDL{//Variables//Constructor//Method (Service) Implementationpublic String getTime() throws CORBA.SystemException{return “Time: “ + new Date().toString();}};// TimeServer_Server.java import CORBA.*;public class TimeServer_Server {public static void main( String[] argv ) { try { CORBA.ORB orb = CORBA.ORB.init();…ObjTestTimeServerImpl obj= new ObjTestTimeServerImpl(…);…// print stringified object reference: System.out.println( orb.object_to_string(obj)); } catch (CORBA.SystemException e){ System.err.println(e); } }};//TimeServer_Client.java import CORBA.*;public class TimeServer_Client{public static void main( String[] argv ) {// pass stringified object reference as argv[0] try {CORBA.ORB orb = CORBA.ORB.init();…CORBA.object obj = orb.string_to_object( argv[0]);…TestTimeServer.ObjTimeServer timeServer = ObjTimeServerHelper.narrow(obj);…System.out.println( timeServer.getTime() );}catch (CORBA.SystemException e) { System.err.println(e); }}};
添加回答
举报
0/150
提交
取消