MustInherit classes

  • Thread starter Thread starter Random
  • Start date Start date
R

Random

What is the proper way of declaring a class so that it only exists as an
inherited class? I have tried every combination I can think of using
Public, Private, Friend... with and without the MustInherit clause.

What I want to acheive is something like the below statements, without a
user being able to instantiate a MySecondClass on it's own.

Public Class MyFirstClass
Public Item1 As String
Public Item2 As String
Public Item3 As MySecondClass_derived

Private Class MySecondClass_derived
Inherits MySecondClass

Public NewItem4a As String
End Class
End Class

Friend MustInherit Class MySecondClass
Public Item4 As String
End Class

To restate, I want the user to refer to an instance of MySecondClass only by
going through MyFirstClass.MySecondClass_derived. I'm thinking this should
actually be an interface, but I am having problems building an interface
that will work with XML Serialization, which this class structure will need
to do.
 
You can make the constructors for that class to be private. That will make
sure that no one can create that object with New().
What is the problem that you are running into?
 
Back
Top