欢迎加我的QQ群:193522571,一起来讨论、交流!

AutoCAD.Net/C#.Net QQ群:193522571 虚拟方法的使用

shell类中有一个虚方法;

而其子类Cylinder、Head及其子类中去实现此虚方法;

这样,在其它类如Main类中可以通过shell及其子类的实例来调用此虚方法;

如:new 一个HeadEllipse  EH

用方法Draw(EH)来实现;

  public class Main
  {
  
public void Draw(Shell shell) { shell.Draw(); } } public class Shell : Part { public virtual ObjectId Draw() { return ObjectId.Null; } } public class Cylinder : Shell { public override ObjectId Draw() { int identify = this.GetCurrentPartIdentity<Cylinder>() + 1; ObjectId id = Draw(identify); this.SetCurrentPartIdentity<Cylinder>(identify); return id; } } public class Head : Shell { } public class HeadEllipse : Head { public override ObjectId Draw() { int identify = this.GetCurrentPartIdentity<HeadEllipse>() + 1; ObjectId id = Draw(identify); this.SetCurrentPartIdentity<HeadEllipse>(identify); return id; } } public class HeadDished : Head { public override ObjectId Draw() { int identify = this.GetCurrentPartIdentity<HeadDished>() + 1; ObjectId id = Draw(identify); this.SetCurrentPartIdentity<HeadDished>(identify); return id; } }

 

posted @ 2021-01-01 16:58  swtool  阅读(133)  评论(0编辑  收藏  举报
欢迎加我的QQ群:193522571,一起来讨论、交流!