473,486 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Inherited code and derived code.

Can inherited code call derived code? If so how.
I have identical 'generic' code that I am repeating again and again
in several derived form because I don't know how to get inherited
code to call derived code. Am I stuck with this situation or is there a
way around it? Below is some sample code.
==============================
Private Sub LoadDataInForm() '= Form_Load
Call FillDataSet()
Call CreateBindings()
Call DataEntryControlsAccessible(False)
Call HideDgColumns()
Call NewCancelSaveCloseButtonState("NewClose")
End Sub

Private Sub RemoveRow() ' RemoveAt button
_bmb.RemoveAt(_bmb.Position)
Call DataEntryControlsAccessible(False)
Call NewCancelSaveCloseButtonState("NewClose")
Call UpdateDataSet()
End Sub
==============================
Most of the calls call code in the derived forms.
Is there a way around duplicating this code in every form?

- Doug

Nov 21 '05 #1
3 1494
dbuchanan,
| Can inherited code call derived code? If so how.
It sounds like you wan to use the Template Method pattern.

In your base form define the method to call Overridable methods that the
derived form overrides.

Something like:

Public Class BaseForm
Inherits System.Windows.Forms.Form

| Private Sub LoadDataInForm() '= Form_Load
| Call FillDataSet()
| Call CreateBindings()
| Call DataEntryControlsAccessible(False)
| Call HideDgColumns()
| Call NewCancelSaveCloseButtonState("NewClose")
| End Sub

Protected Overridable Sub FillDataSet()
Throw New NotImplementedException()
End Sub

Protected Overridable Sub CreateBindings()
Throw New NotImplementedException()
End Sub

...

End Class

Public Class DerivedForm
Inherits BaseForm

Protected Overrides Sub FillDataSet()
' fill the data set object
End Sub

Protected Overrides Sub CreateBindings()
' create the data bindings
End Sub

...

End Class

Depending on the requirements of the Template method & the base class I will
make the stub routines (FillDataSet & CreateBindings) MustOverride instead
of Overridable as the derived class is required to override them, however in
the case of a Form, you cannot use MustOverride as it interferes with the
designer... using a couple "#if debug" you can have the method MustOverride
in the release builds & Overridable in the debug builds...

Hope this helps
Jay
"dbuchanan" <db*********@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
| Can inherited code call derived code? If so how.
| I have identical 'generic' code that I am repeating again and again
| in several derived form because I don't know how to get inherited
| code to call derived code. Am I stuck with this situation or is there a
| way around it? Below is some sample code.
| ==============================
| Private Sub LoadDataInForm() '= Form_Load
| Call FillDataSet()
| Call CreateBindings()
| Call DataEntryControlsAccessible(False)
| Call HideDgColumns()
| Call NewCancelSaveCloseButtonState("NewClose")
| End Sub
|
| Private Sub RemoveRow() ' RemoveAt button
| _bmb.RemoveAt(_bmb.Position)
| Call DataEntryControlsAccessible(False)
| Call NewCancelSaveCloseButtonState("NewClose")
| Call UpdateDataSet()
| End Sub
| ==============================
| Most of the calls call code in the derived forms.
| Is there a way around duplicating this code in every form?
|
| - Doug
|
Nov 21 '05 #2
Jay,

It works!

You refer to the "template method" pattern. Where can I learn more
about this and other patterns?

Thank you.
-Doug

Nov 21 '05 #3
Doug,
The "Template Method" pattern is defined in the Gang of Four's (GOF) book
"Design Patterns - Elements of Reusable Object-Oriented Software" from
Addison Wesley, it is IMHO a "must have" book for the serious OO developer.
Design Patterns provide programmers with a convenient way to reuse
object-oriented code & concepts amount programmers and across projects,
offering easy, time-saving solutions to commonly recurring problems in
software design. The GOF are Erich Gamma, Richard Helm, Ralph Johnson, and
John Vlissides.

James W. Cooper's book "Visual Basic Design Patterns - VB 6.0 and VB.NET" is
also a "must have" book that is an excellent companion to the above GOF
book. Cooper's book gives the VB6 & VB.NET view of each pattern in the GOF
book.

I would ultimately recommend both books. However! If you can't afford both
of the above books I would recommend the first if you can read & understand
C++, otherwise I would recommend the second if you only can read &
understand VB...

The C# version of Cooper's book was available on the internet, not sure if
it still is. There are numerous sites (some better then others) that cover
the above design patterns & others...

Hope this helps
Jay
"dbuchanan" <db*********@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
| Jay,
|
| It works!
|
| You refer to the "template method" pattern. Where can I learn more
| about this and other patterns?
|
| Thank you.
| -Doug
|
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4317
by: Dave | last post by:
Hello NG, Regarding access-declarations and member using-declarations as used to change the access level of an inherited base member... Two things need to be considered when determining an...
3
1240
by: M O J O | last post by:
Hi, I've created a MasterForm which all my forms in my project must derive from. In my MasterForm, I've overloaded the New event with this code: Public Sub New(ByVal SomeText As String)...
2
1765
by: twawsico | last post by:
I ran into this while converting some DX C# code to VB.NET (VS 2003), and I'm just curious as to whether this is intended behavior (and if so, where might I read up on it) or more of a bug. This...
4
3732
by: dbuchanan | last post by:
Is the following behavior normal? Both the 'Protected sub' in the inherited form and the 'Private Shadows sub' in the derived form fires. My interpretation of MSDN help on the topic "Shadows"...
6
7696
by: rob.bowley | last post by:
I have a class which inherits from a generated abstract base class. I simply want to hide some fields which are inherited from the base class when it is serialised. I have tried: public...
6
1745
by: Peter Oliphant | last post by:
I just discovered that the ImageList class can't be inherited. Why? What could go wrong? I can invision a case where someone would like to add, say, an ID field to an ImageList, possible so that...
3
5456
by: Wayne Brantley | last post by:
VS2005 RTM Create a web user control to use as a base class for other web user controls. Now, create a new web user control, change the class it inherits from to your base class and compile....
12
1487
by: Mike - EMAIL IGNORED | last post by:
Within class MyClass, I can think of two ways to tell if MyClass is inherited in a particular use: 1. pass an appropriate bool in the ctor args; 2. use a virtual method that returns, for...
19
2206
by: jan.loucka | last post by:
Hi, We're building a mapping application and inside we're using open source dll called MapServer. This dll uses object model that has quite a few classes. In our app we however need to little bit...
0
7099
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7319
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3069
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.