Jay B. Harlow said:
Bernard,
In addition to the other comments, you could use one or more Interfaces:
Something like:
Public Interface IFluid
Property Pressure() As Integer
Property Temp() As Integer
Property FlowRate() As Integer
End Interface
Public Class Fluid
Implements IFluid
Private m_flowRate As Integer
Private m_pressure As Integer
Private m_temp As Integer
Public Property FlowRate() As Integer Implements IFluid.FlowRate
Get
Return m_flowRate
End Get
Set(ByVal value As Integer)
m_flowRate = value
End Set
End Property
Public Property Pressure() As Integer Implements IFluid.Pressure
Get
Return m_pressure
End Get
Set(ByVal value As Integer)
m_pressure = value
End Set
End Property
Public Property Temp() As Integer Implements IFluid.Temp
Get
Return m_temp
End Get
Set(ByVal value As Integer)
m_temp = value
End Set
End Property
End Class
Public Interface IDrop
Property Diameter() As Integer
Property Temp() As Integer
Property Pressure() As Integer
End Interface
Public Class Drop
Implements IDrop
Private m_diameter As Integer
Private m_pressure As Integer
Private m_temp As Integer
Public Property Diameter() As Integer Implements IDrop.Diameter
Get
Return m_diameter
End Get
Set(ByVal value As Integer)
m_diameter = value
End Set
End Property
Public Property Pressure() As Integer Implements IDrop.Pressure
Get
Return m_pressure
End Get
Set(ByVal value As Integer)
m_pressure = value
End Set
End Property
Public Property Temp() As Integer Implements IDrop.Temp
Get
Return m_temp
End Get
Set(ByVal value As Integer)
m_temp = value
End Set
End Property
End Class
Public Interface ISection
Inherits IFluid
Inherits IDrop
End Interface
Public Class Section
Implements ISection
Private m_flowRate As Integer
Private m_pressure As Integer
Private m_temp As Integer
Private m_diameter As Integer
Public Property FlowRate() As Integer Implements IFluid.FlowRate
Get
Return m_flowRate
End Get
Set(ByVal value As Integer)
m_flowRate = value
End Set
End Property
Public Property Pressure() As Integer Implements IFluid.Pressure,
IDrop.Pressure
Get
Return m_pressure
End Get
Set(ByVal value As Integer)
m_pressure = value
End Set
End Property
Public Property Temp() As Integer Implements IFluid.Temp, IDrop.Temp
Get
Return m_temp
End Get
Set(ByVal value As Integer)
m_temp = value
End Set
End Property
Public Property Diameter() As Integer Implements IDrop.Diameter
Get
Return m_diameter
End Get
Set(ByVal value As Integer)
m_diameter = value
End Set
End Property
End Class
Then rather then define your parameters as the class, you would define them
as the Interface.
For Example:
Public Shared Sub ProcessFluid(ByVal aFluid As IFluid)
Debug.WriteLine(CObj(aFluid).GetType().Name)
Debug.Indent()
Debug.WriteLine(aFluid.Pressure, "Fluid.Pressure")
Debug.WriteLine(aFluid.Temp, "Fluid.Temp")
Debug.WriteLine(aFluid.FlowRate, "Fluid.FlowRate")
Debug.Unindent()
End Sub
Public Shared Sub ProcessDrop(ByVal aDrop As IDrop)
Debug.WriteLine(CObj(aFluid).GetType().Name)
Debug.Indent()
Debug.WriteLine(aDrop.Diameter, "Drop.Diameter")
Debug.WriteLine(aDrop.Temp, "Drop.Diameter")
Debug.WriteLine(aDrop.Pressure, "Drop.Pressure")
Debug.Unindent()
End Sub
Public Shared Sub Main()
Dim aFluid As New Fluid
Dim aDrop As New Drop
Dim aSection As New Section
ProcessFluid(aFluid)
ProcessFluid(aSection)
ProcessDrop(aDrop)
ProcessDrop(aSection)
End Sub
Note you don't need to use three actual interface, you can get by with only
defining Fluid or Drop in terms on an interface, then Section could inherit
from the other & implement the interface. The key is to use the Interface
instead of the class when you want to accept a Section in addition to the
class... Section could also implement ISection by using delegation to actual
Fluid & Drop objects...
Hope this helps
Jay