zoukankan      html  css  js  c++  java
  • 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; } }
  • 相关阅读:
    unity-TextAsset
    unity-热更-InjectFix
    进程和线程的区别
    StringBuffer 和 StringBuilder 的区别
    List、Set、Map 三者区别
    竞态条件是什么?
    多线程安全(synchronized、三大特性、生命周期以及优缺点)
    集合的同步与非同步
    List、Set、Map的了解及区别
    java面试题
  • 原文地址:https://www.cnblogs.com/swtool/p/14220352.html
Copyright © 2011-2022 走看看