Inheritance Advice

  • Thread starter Thread starter Cameron Frasnelly
  • Start date Start date
C

Cameron Frasnelly

Hi All,

I'm fairly new to this OOP and have a quick question:

I have a Work Order class that has properties that are common to all my work
orders. I then have a class that inherits from this class and adds some
properties.

I want each of these classes to have a procedure called WO_Update but I'm
not sure if I can copy the code from the original class and add to it in the
inherited class (so it updates all the original classes properties and the
added ones) or if I could have a procedure with the same name that runs the
parents procedure first (I'm not sure how I would reference this). This
function just updates all the fields in the database but I have to update
some additional fields in a different table for the inherited class. Any
thoughts on how to best accomplish this would be appreciated!! Hope that
makes sense...

Cameron
 
Hi Cameron,

Your query makes perfect sense :-)

Stick the following into a Form and run it. It will show you how
inheritance works.

Public Class frmMain
Private Sub frmMain_Load(....) Handles MyBase.Load
Dim BW As New WorkOrder
BW.Name = "Biggin"
BW.Update

Dim DW As New DerivedWorkOrder
DW.Name = "Derby"
DW.Update
End Sub
End Class

Public Class WorkOrder
Public Name As String
Public Overridable Sub Update
MessageBox.Show ("Updating Base (" & Name & ")")
End Sub
End Class

Public Class DerivedWorkOrder : Inherits WorkOrder
Public Overrides Sub Update
MyBase.Update
MessageBox.Show ("Updating Derived (" & Name & ")")
End Sub
End Class

As you can see in Sub Update in the DerivedWorkOrder, it calls
MyBase.Update. Using MyBase is how a class accesses the members of the class
that it was derived from.

The Overridable keyword says that the derived class may have a method with
the same name. [There is another way - Shadows - but we'll leaver that one for
now].

Regards,
Fergus
 
Back
Top