You could use interfaces for this. Define an interface that has all the
common methods and make each class Implement that interface. You then use
the interface as a type when passing the objects.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim objA As New MyObjectA()
Dim objB As New MyObjectB()
DoSomething(objA)
DoSomething(objB)
End Sub
Public Sub DoSomething(ByVal obj As IMyInterface)
MsgBox(obj.Name)
MsgBox(obj.Method)
End Sub
Interface IMyInterface
ReadOnly Property Name() As String
Function Method() As Boolean
End Interface
Class MyObjectA
Implements IMyInterface
Public Function Method() As Boolean Implements
Test.Form1.IMyInterface.Method
' Do your object specific code in here and return True on
success
Return True
End Function
Public ReadOnly Property Name() As String Implements
Test.Form1.IMyInterface.Name
Get
Return "MyObjectA"
End Get
End Property
End Class
Class MyObjectB
Implements IMyInterface
Public Function Method() As Boolean Implements
Test.Form1.IMyInterface.Method
' Do your object specific code in here and return True on
success
Return True
End Function
Public ReadOnly Property Name() As String Implements
Test.Form1.IMyInterface.Name
Get
Return "MyObjectB"
End Get
End Property
End Class
-----Original Message-----
From: Robert Sindall [mailto:rsindall@z...]
Sent: Wednesday, December 18, 2002 3:11 PM
To: pro_VB_dotnet
Subject: [pro_vb_dotnet] Class and Type Help? -- Please
Hi
I have 12 classes, of which they have different properties but identical
functions, But I want to have a controling workflow class which will allow
for me to add more classes than 12 but without having to recode the workflow
class...
eg
Class EventDetails
EventID
EventName
'etc...
Public Function AddEventDetails(ByVal EventDetails as EventDetails) as
Boolean
'etc...
End Function
and same for Article
Class ArticleDetails
ArticleID
ArticleName
'etc...
Public Function AddArticleDetails(ByVal ArticleDetails as ArticleDetails) as
Boolean
'etc...
End Function
'
Class WorkFlow
Public Function AddItem(ByVal DataObj As Object) As Boolean
'get type of Object
Dim ObjType As Type = DataObj.GetType()
'get class name as string
Dim ClassName As String = ObjType.Name
'create new object of classname and set equal to DataObj
Dim NewDataObj As ClassName = CType(DataObj, ClassName)
'call a standard function they all have ?
NewDataObj.GetFunction("Add" + ClassName + "(" + DataObj + ")")
---
VB.NET Handbooks Library Special Offer
Get a massive 40% off this complete library
of books (US residents only at the moment).
Free ground shipping on this 10 book bundle!
http://www.wroxdirect.com/proddescription.asp?Bookselect=BUN10E004