vb.net - How can I make a base class method access one of its derived class's shadowed properties? -


given example:

imports system  public module module1 public sub main()     console.writeline("expect 'wheelvalue' here.")     dim car new car()     car.dosomething()      console.writeline("expect 'fordwheelvalue' here.")     dim ford new ford()     ford.dosomething() end sub  public class car     public sub dosomething()         console.writeline("car.dosomething()")         console.writeline("wheel=" + wheel.value)         console.writeline(environment.newline)     end sub     public property wheel new wheel() end class  public class ford     inherits car     public shadows property wheel new fordwheel()         end class  public class wheel     public value string = "wheelvalue" end class  public class fordwheel     public value string = "fordwheelvalue" end class end module 

calls ford.dosomething() use base class's property wheel.value. in interest of not duplicating code, there way using vb write cleanly these calls ford.dosomething() instead grab instance of ford's property fordwheel.value? seems might need language feature "shadows overrides" - isn't supported in vb can tell.

you redefine type of wheel using inside ford class. wheel doesn't need defined in ford anymore, since signature same. fordwheel descendant of wheel , overrides value property.

public class car      public sub new()         wheel = new wheel()     end sub      public sub dosomething()         console.writeline("car.dosomething()")         console.writeline("wheel=" + wheel.value)         console.writeline(environment.newline)     end sub      public property wheel wheel end class  public class ford     inherits car      public sub new()         wheel = new fordwheel()     end sub  end class  public class wheel     public overridable property value string = "wheelvalue" end class  public class fordwheel     inherits wheel      public overrides property value string = "fordwheelvalue" end class 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -