another inheritance question

  • Thread starter Thread starter Craig Buchanan
  • Start date Start date
C

Craig Buchanan

I have a class named "Generic" and a second class named "Specific" which
inherits from Generic. I have a Save method in the Generic class. I don't
have an override in the Specific class. If I call Specific.Save, is there a
way for the Generic class's logic to route back to methods of the Specific
class?

Thanks,

Craig Buchanan
 
no
a eventual solution is

public mustinherit class generic
protected sub Save(someinfo as object)
....
end save
public mustoverride sub Save()
end class

public class specific
inherits generic
public overrides sub Save()
save(mySpecificExtraInfoObject)
end sub
end class


hope this helps

dominique
 
Or you could call

mybase.save

Dominique Vandensteen said:
no
a eventual solution is

public mustinherit class generic
protected sub Save(someinfo as object)
...
end save
public mustoverride sub Save()
end class

public class specific
inherits generic
public overrides sub Save()
save(mySpecificExtraInfoObject)
end sub
end class


hope this helps

dominique


there
 
if i understand correctly you cannot :-)

in generic.save (mybase.save) he needs info only available in specific
so specific has to pass something to generic...
-> mybase.save("stuff")


or i didn't understand correctly and i'm telling a lot of junk :-)
 
Craig,
In addition to Dominique's answer:

It sounds like what you want is a Template Method Pattern. (Dominique showed
a variation of a Template Method).

http://www.dofactory.com/Patterns/PatternTemplate.aspx

Another variation of the Template Method is:

Public MustInherit Class Generic

Public Sub Save()
BeforeSave()
' do the save
AfterSave()
End Sub

Protected MustOverride Sub BeforeSave()
Protected MustOverride Sub AfterSave()

End Class

Public Class Specific
Inherits Generic

Protected Overrides Sub BeforeSave
End Sub

Protected Overrides Sub AfterSave
End Sub

End Class

Alternative BeforeSave & AfterSave can be Overridable, allowing Generic to
offer a "default" implementation that Specific can replace if it needs to...

Of course BeforeSave & AfterSave could have parameters or be functions or
properties returning values.

Hope this helps
Jay
 
Back
Top