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; } }
  • 相关阅读:
    ROS 学习遇到的问题记录(持续更新)
    09.07 jQuery 随意整理
    JavaScript 随意整理3
    JavaScript 随意整理2
    css 随意整理 08.08
    html 随意整理
    vue day2
    vue day1
    【copy】必备之常用正则表达式 By 其他博主
    note.js 笔记第二课
  • 原文地址:https://www.cnblogs.com/swtool/p/14220352.html
Copyright © 2011-2022 走看看