public interface IServerObject { Person GetPersonInfo(string name,string sex,int age); } public interface IServerObjFactory { IServerObject CreateInstance(); } public class ServerObject:MarshalByRefObject,IServerObject { public Person GetPersonInfo(string name,string sex,int age) { Person person = new Person(); person.Name = name; person.Sex = sex; person.Age = age; return person; } } public class ServerObjFactory:MarshalByRefObject,IServerObjFactory { public IServerObject CreateInstance() { return new ServerObject(); } }
然后再客户端的远程对象中只提供工厂接口和原来的对象接口:
客户端调用
ServerRemoteObject.IServerObject serverObj = serverFactory.CreateInstance();
时间: 2024-10-13 16:37:00