3 回答
TA贡献1802条经验 获得超5个赞
接口不能被实例化。IA ia=new A()。实例化的是类A。 IA ia=a as IA ;之所以能进行转换,是因为A集成了接口IA。可以搜下 里氏替换原则。
IMap pmap=axmapcontrol1.Map;至于 这一句, ArcEngine我没使用过,但是 axmapcontrol1.Map应该是类的属性,返回的是继承自IMap接口的子类。
将几个类封装成一个大类,也可以做到。但是这样封装没什么意义。 像你上面说的,IA ia=D.A
D与接口 IA没有继承关系,D只不过是返回一个IA接口的子类而已。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | class Program { static void Main(string[] args) { ITest t = new TestD().b; t.GetTest(); Console.ReadKey(); } } public interface ITest { void GetTest();
} public class TestD { public TestA a { get { return new TestA(); } } public TestB b { get { return new TestB(); } } } public class TestA : ITest { public void GetTest() { Console.WriteLine("这是A"); } } public class TestB: ITest { public void GetTest() { Console.WriteLine("这是B"); } } |
TA贡献1851条经验 获得超5个赞
接口不能实例化,只能被实现
IMap pmap=axmapcontrol1.Map
pmap 是接口指针 Map是IMap的实现,也是axmapcontrol1的属性。
- 3 回答
- 0 关注
- 1310 浏览
添加回答
举报