Inheritance

  • Thread starter Thread starter Kalim Julia
  • Start date Start date
K

Kalim Julia

Public Class RichBigDaddy
Public Sub PlayPolo()
Trace.WriteLine("RichBigDaddy::PlayPolo")
End Sub
End Class
Public Class TrustFundSnob
Inherits RichBigDaddy

Public Sub PlayPolo()
Trace.WriteLine("TrustFundSnob::PlayPolo")
End Sub
End Class=================================================If I want the
output be :RichBigDaddy::PlayPoloTrustFundSnob::PlayPoloAny sub declaration
method should be added ? (like shadows, overrides, overloads, etc)I've tried
to use them all, but the output is only
:RichBigDaddy::PlayPoloORTrustFundSnob::PlayPolo
 
You want it to print the two lines when calling the PlayPolo of the
TrustFundSnob?
Than change it to this:

Public Class TrustFundSnob
Inherits RichBigDaddy
Public Sub PlayPolo()
MyBase.PlayPolo4 '-> ADD THIS LINE
Trace.WriteLine("TrustFundSnob::PlayPolo")
End Sub
End Class

I hope this is what you want?
 
Kalim,

Is this what you want to do?

\\\\
Public Class RichBigDaddy
Public Overridable Sub PlayPolo()
Trace.WriteLine("RichBigDaddy::PlayPolo")
End Sub
End Class
Public Class TrustFundSnob
Inherits RichBigDaddy
Public Overrides Sub PlayPolo()
MyBase.PlayPolo()
Trace.WriteLine("TrustFundSnob::PlayPolo")
End Sub
End Class
///

I hope this helps,

Cor
 
I design this and hoping that my programmers won't do any mistakes like
forgetting put MyBase.PlayPolo().
I just want to reduce the mistakes (something like trigger or store
procedure in database system).
Why people made it, because they want to reduce problems.
 
As your programmers use that class than that myBase.PlayPolo is in it so
what is the trouble?

Cor
 
Kalim Julia said:
I design this and hoping that my programmers won't do any mistakes
like forgetting put MyBase.PlayPolo().
I just want to reduce the mistakes (something like trigger or store
procedure in database system).
Why people made it, because they want to reduce problems.


In VB 2005, the IDE automatically inserts mybase.proc if you override a
procedure.


Armin
 
Sort of....

It depends upon how many levels of inheritance you want / will allow.

If your developers are just going to inherit from it ONCE and you will
ALWAYS want the base functionality to be called then you can try


Public Class RichBigDaddy
Public Sub PlayPolo()
Trace.WriteLine("RichBigDaddy::PlayPolo")
PlayPoloEx()
End Sub
Protected Overridable Sub PlayPoloEx()
End Sub
End Class

Public Class TrustFundSnob
Inherits RichBigDaddy

Protected Overrides Sub PlayPoloEx()
Trace.WriteLine("TrustFundSnob::PlayPolo")
End Sub

End Class


Your developers implement the nnnEx() version of the function.
If you want to enforce implementing it, then make it MustOverrride in
the base class, else just leave as is.


Dim x as New RichBigDaddy
x.PlayPolo()

=> "RichBigDaddy::PlayPolo"

Dim y as New TrustFundSnob
y.PlayPolo()

=> "RichBigDaddy::PlayPolo"
"TrustFundSnob::PlayPolo"


In more complicated cases - multiple levels of inheritance; want to
invoke the method at each level - I would not swear that one could not
use reflection to invoke each version but I would REALLY advise against
it. The cure would be solution would be worse thant the original
problem

hth,Alan
 
Alan,
Instead of PlayPoloEx, I would consider calling it PlayPoloCore, as using
Core is one of the "patterns" that the framework uses. For example
Control.Scale calls Control.ScaleCore to do the "heavy lifting".

http://msdn.microsoft.com/library/d...temwindowsformscontrolclassscalecoretopic.asp

I want to say the above "pattern" is in the "Framework Design Guidelines",
however I'm not seeing a specific reference for it in either .NET 1.x or 2.0
Design Guidelines...

I've also used the convention of calling the overridable method DoPlayPolo &
OnPlayPolo...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


|
|
| Sort of....
|
| It depends upon how many levels of inheritance you want / will allow.
|
| If your developers are just going to inherit from it ONCE and you will
| ALWAYS want the base functionality to be called then you can try
|
|
| Public Class RichBigDaddy
| Public Sub PlayPolo()
| Trace.WriteLine("RichBigDaddy::PlayPolo")
| PlayPoloEx()
| End Sub
| Protected Overridable Sub PlayPoloEx()
| End Sub
| End Class
|
| Public Class TrustFundSnob
| Inherits RichBigDaddy
|
| Protected Overrides Sub PlayPoloEx()
| Trace.WriteLine("TrustFundSnob::PlayPolo")
| End Sub
|
| End Class
|
|
| Your developers implement the nnnEx() version of the function.
| If you want to enforce implementing it, then make it MustOverrride in
| the base class, else just leave as is.
|
|
| Dim x as New RichBigDaddy
| x.PlayPolo()
|
| => "RichBigDaddy::PlayPolo"
|
| Dim y as New TrustFundSnob
| y.PlayPolo()
|
| => "RichBigDaddy::PlayPolo"
| "TrustFundSnob::PlayPolo"
|
|
| In more complicated cases - multiple levels of inheritance; want to
| invoke the method at each level - I would not swear that one could not
| use reflection to invoke each version but I would REALLY advise against
| it. The cure would be solution would be worse thant the original
| problem
|
| hth,Alan
|
 
Back
Top