I'm relatively new to OOP. Let's say I have three different objects/classes defined, like:
Public Class Part
Private m_Name As String = ""
Public Property Name() As String
Get
Return m_Name
End Get
End Property
something...
End Class
Public Class Assembly
Private m_Name As String = ""
Public Property Name() As String
Get
Return m_Name
End Get
End Property
something...
End Class
Public Class Drawing
Private m_Name As String = ""
Public Property Name() As String
Get
Return m_Name
End Get
End Property
something...
End Class
Now I have a list of all instances of those objects in another class, like:
Public Class Main
Private m_ListOfObjects As List(Of Objects)
Private Sub run()
something...
End Sub
End Class
Imagine a code which adds each instance of those three classes (Part, Assembly and Drawing) to this m_ListOfObjects
. Now I have a loop which loops trough the whole list, like:
Dim Obj As Object
For Each Obj In m_ListObObjects
Debug.Print(Obj.Name)
End For
My questions is now: IntelliSense is not able to show me if the property Name
exists for the Object Obj
. Well that's clear because Visual Studio does not know that I will use the classes Part
, Assembly
and Drawing
for. How can I solve that issue?
It feels like a hacky way when I use something like this:
CType(Obj, Part).Name
Then Visual Studio knows that I refer to the Part
Class, but what can I do if I loop through different objects in a list and refer to a property each class will have? Or maybe my approach is completely off the track of OOP? Do I miss the opportunity to implement an interface?