VB.Net Polymorphism: functions existing only in derived class
<p>Greetings StackOverflow community. I have only a very basic foundation in programming, and have been teaching myself VB.Net at my job to automate some lab procedures. I'm trying to transition my coding practice into more modular OOP formats, and I'm encountering something that I need help understanding. I'm also using this as an opportunity to teach myself something. Please excuse if I get some terminology wrong, I'll provide code to demonstrate what I mean.</p>

<p>I'm creating a library to simplify controlling various pieces of lab equipment (Power supplies, temperature chambers, motion stages, and other more specialized equipment). I've declared a parent class, Device:</p>

<pre><code>Public Class Device
Protected port As String = ""

Protected Property comPort() As String
    Get
        Return port
    End Get
    Set(value As String)
        port = value
    End Set
End Property
End Class
</code></pre>

<p>And a subclass to control a temp chamber:</p>

<pre><code>Public Class Watlow96
Inherits Device

Public Sub New()
    port = ""
End Sub

Public Sub New(ByVal comPort As String)
    port = comPort
End Sub

''' &lt;summary&gt;
''' Send temperature command to the chamber
''' &lt;/summary&gt;
''' &lt;param name="temp"&gt;Commanded temperature (type Single)&lt;/param&gt;
''' &lt;returns&gt;False if COM port unavailable, True otherwise&lt;/returns&gt;
Public Overrides Function setTemp(ByVal temp As Single) As Boolean '
    blah blah blah, stuff that does things
End Function

''' &lt;summary&gt;
''' Reads current temp of chamber.
''' &lt;/summary&gt;
''' &lt;returns&gt;Current temp as type Single&lt;/returns&gt;
Public Overrides Function getTemp() As Single '
    blah blah blah, stuff that does other things
End Function

''' &lt;summary&gt;
''' Reads current temp of chamber.
''' &lt;/summary&gt;
''' &lt;returns&gt;Current temp as type String&lt;/returns&gt;
Public Overrides Function getTempString() As String '
    Return Convert.ToString(getTemp())
End Function
End Class
</code></pre>

<p>In a small tester program, I declare the chamber as a device:</p>

<pre><code>Dim chamber As New Device
</code></pre>

<p>and instantiate it as a Watlow96, taking advantage of Polymorphism:</p>

<pre><code>chamber = New Watlow96("COM25")
</code></pre>

<p>So far, no errors. It was my original understanding that upon instantiating the object/variable, it becomes whatever class it was instantiated as. Given that I get errors when trying to call Watlow96 functions on something declared as a Device, I must assume this is incorrect.</p>

<p>I've gotten around this issue in a couple of different ways while tinkering. One is to create empty overridable functions in my base class Device. This is undesirable because I have a myriad of equipment to control most of it with a lot of functions and that would create a lot of useless empty function declarations in Device.</p>

<p>The other way is to declare the chamber as a Watlow96 instead of Device. I think that perhaps this is the correct way, but I wanted to ask the smart folks to see if this is the case (and the appropriate way of dealing with this situation) or if I missed something in my understanding and structuring.</p>

<p>The other consideration is of course the necessity of having the base class Device at all since it really only indicates that the devices has a COM port. I implemented it as a way to try to understand inheritance and polymorphism.</p>

<p>Thanks in advance for the help.</p>