Your line of thinking is understandable, you just need to take it one step further.
Public MustInherit Class BaseClass
Protected MustOverride Sub MethodA()
Protected MustOverride Sub MethodB()
...stuff
Protected MustInherit Class PDFOperations
Protected MustOverride Sub Method1()
Protected MustOverride Sub Method2()
etc.
End Class
Protected MustOverride ReadOnly Property PDF
End Class
Simply making the nested class abstract isn't enough to require that the inherited class actually implement them (as you don't actually reference that class anywhere). .NET nested classes are similar to nested static
classes in Java, in that they have no reference to a specific instance of the containing class, they're simply grouped, for lack of a better term, by the outer class and have access to the private, protected, and internal members of the containing class.
By providing an abstract readonly property that is of the abstract inner class's type, you then require that the inheriting class provide SOME concrete implementation of it and should break up your methods just as you like.
Edit
While it isn't possible to absolutely enforce that EVERY class that inherits from BaseClass
provide a distinct implementation of the PDFOperations
class, this is enforced from a practical perspective because any class that inherits from PDFOperations
will have to be a Protected
nested class of the class that inherits from BaseClass
. This means that they cannot share implementations.
Examples
Public Class DerivedOne Inherits BaseClass
Protected Overrides Sub MethodA() ...
Protected Overrides Sub MethodB() ...
Private pdfInstance as PDFOne
Protected Class PDFOne Inherits PDFOperations
Protected Overrides Sub Method1() ...
Protected Overrides Sub Method2() ...
Private instance as DerivedOne
Public Sub New(ByVal instance as DerivedOne)
Me.instance = instance
End Sub
End Class
Protected Overrides ReadOnly Property PDF
Get
If pdfInstance is Nothing Then pdfInstance = new PDFOne(Me)
return pdfInstance
End Get
End Property
End Class
Public Class DerivedTwo Inherits BaseClass
Protected Overrides Sub MethodA() ...
Protected Overrides Sub MethodB() ...
Private pdfInstance as PDFTwo
Protected Class PDFTwo Inherits PDFOperations
Protected Overrides Sub Method1() ...
Protected Overrides Sub Method2() ...
Private instance as DerivedTwo
Public Sub New(ByVal instance as DerivedTwo)
Me.instance = instance
End Sub
End Class
Protected Overrides ReadOnly Property PDF
Get
If pdfInstance is Nothing Then pdfInstance = new PDFTwo(Me)
return pdfInstance
End Get
End Property
End Class
In PDFOne
and PDFTwo
, there is an instance variable called instance
that represents a reference to the containing object that inherits from BaseClass