I have two classes called Relationship and Employment and they are declared as follows:
Public Class Relationship
Inherits BusinessBase(Of Relationship)
...
End Class
Public Class Employment
Inherits Relationship
...
End Class
I then want to create a collection class called Employments, which I declared as follows:
Public Class Employments
Inherits BusinessListBase(Of Employments, Employment)
...
End Class
The problem is that I get the following error: "Type argument 'Employment' does not inherit from or implement the constraint type 'BusinessBase(Of Employment)'"
I'm kinda new to Generics, and that's what I'm suspecting is causing this issue. Any ideas on how to solve it? I know I could probably use composition instead of inheritance, but in this particular case (using the "behaves-as" or "is-a" test), inheritance makes the most sense. Any ideas?
Thanks,
John Delano
Okay, I'm sorry... I left out a critical piece of information...
I'm trying to create my own "BusinessBase-like" generic class. All of my business objects have the same exact type of ID (Integer) and they all have a Description, so I thought I'd encapsulate that in a "MyProjectBase" class (which inherits from BusinessBase). I also wanted to create my own generic "MyProjectListBase" class (which inherits from BusinessListBase) to handle the Assign, GetItem, Remove, Contains, etc. in one place (do I even need to implement these, by the way?), so here's what I did...
Public MustInherit Class MyProjectBase(Of T as MyProjectBase(Of T))
Inherits BusinessBase(Of T)
...
End Class
Public MustInherit Class MyProjectListBase(Of T as MyProjectListBase(Of T, C), C As MyProjectBase(Of C))
Inherits BusinessListBase(Of T, C)
...
End Class
Then, I declared the classes from my first post as follows:
Public Class Relationship
Inherits MyProjectBase(Of Relationship)
...
End Class
Public Class Employment
Inherits Relationship
...
End Class
Public Class Employments
Inherits MyProjectListBase(Of Employments, Employment)
...
End Class
Then I get the error I mentioned in my first post. So, I did some thinking after your comment that BusinessListBase's type constraint is IEditableBusinessObject, and I did the same thing in the MyProjectListBase class, and then it worked. The only problem is that now MyProjectListBase doesn't know about any of the fields/properties I've declared in MyProjectBase. In order to implement that functionality, do I need to create another layer of inheritance that isn't generic and stick it in the middle somehow? If so, do you have any ideas on how (i.e. syntax) I would need to accomplish that?
I guess the worst case scenario is that I'll have to implement common collection methods in all my collection classes... not the end of the world, I guess.
Thanks for any help,
John Delano
I'm trying to create my own "BusinessBase-like" generic class. All of my business objects have the same exact type of ID (Integer) and they all have a Description, so I thought I'd encapsulate that in a "MyProjectBase" class (which inherits from BusinessBase). I also wanted to create my own generic "MyProjectListBase" class (which inherits from BusinessListBase) to handle the Assign, GetItem, Remove, Contains, etc. in one place (do I even need to implement these, by the way?), so here's what I did...
Thanks, Rocky! That's perfect! I don't know why I didn't think of using an interface before, but that's essentially all I need. Thanks!
John
Copyright (c) Marimer LLC