vb.net - Extending a base class to a derived class -


we have 2 classes basicrace & advancedrace. advancedrace inherits basicrace

i have basicrace want 'convert' advanced class.

see code below example:

module module1     sub main()         dim brace new basicrace {.courseid = 1, .meetingdate = "2013-05-01", .racenumber = 1}         dim arace new advancedrace          ' upgrade brace advancedrace???????     end sub end module  public class basicrace     public property meetingdate date     public property courseid integer     public property racenumber integer end class  public class advancedrace     inherits basicrace     public property racetitle string end class 

any great - i'm starting think can not done unless write function convert basicrace advancedrace going through each property 1 one?

you can't "convert" base class subclass such (you can't change type of existing object), can create new instance of subclass copies properties base class.

typical ways of implementing classes might be:

  • a constructor in advancedrace takes basicrace parameter , copies properties it
  • a static method in advancedrace takes basicrace parameter, creates new object copied properties, , returns it

it's worth noting result in 2 separate objects (one of each type) aren't linked @ - changes in advancedrace object won't reflected in basicrace or vice-versa.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -