473,612 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ 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 DataEntryContro lsAccessible(Fa lse)
Call HideDgColumns()
Call NewCancelSaveCl oseButtonState( "NewClose")
End Sub

Private Sub RemoveRow() ' RemoveAt button
_bmb.RemoveAt(_ bmb.Position)
Call DataEntryContro lsAccessible(Fa lse)
Call NewCancelSaveCl oseButtonState( "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 1503
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 DataEntryContro lsAccessible(Fa lse)
| Call HideDgColumns()
| Call NewCancelSaveCl oseButtonState( "NewClose")
| End Sub

Protected Overridable Sub FillDataSet()
Throw New NotImplementedE xception()
End Sub

Protected Overridable Sub CreateBindings( )
Throw New NotImplementedE xception()
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*********@ho tmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.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 DataEntryContro lsAccessible(Fa lse)
| Call HideDgColumns()
| Call NewCancelSaveCl oseButtonState( "NewClose")
| End Sub
|
| Private Sub RemoveRow() ' RemoveAt button
| _bmb.RemoveAt(_ bmb.Position)
| Call DataEntryContro lsAccessible(Fa lse)
| Call NewCancelSaveCl oseButtonState( "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*********@ho tmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.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
4332
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 inherited base member's access level in the derived class: its access level in the base class and the type of inheritance (public, protected, or private). After this determination is made, the following possibilities exist for manually changing the...
3
1244
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) MyBase.New()
2
1774
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 involves creating a New instance of a derived class that inherits a base class. In C#, private member vars in the derived class ( e.g. private MySimpleObject MyObject = new MySimpleObject();) are instantiated immediately when the the calling code...
4
3744
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" does not seem to indicate that this is the designed behavior. (the topic is rather cryptic to me. Here is my code;
6
7709
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 class Details : GeneratedDetails {
6
1760
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 the individual elements in an array of ImageList's could be identified by the ID, thereby allowing re-ordering the array without harm. A person could identify by index into the array, but that would not be preserved by re-ordering (and re-ordering...
3
5468
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. (You must have a <% Register %> so it will see it) You will get TWO warnings per class like:
12
1501
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 example, a siring containing the class name. Is there a better way?
19
2223
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 modify come of the classes so they match our purpose better - mostly add a few methods etc. Example: Open source lib has classes Map and Layer defined. The relationship between them is one to many. We created our own versions (inherited) of Map...
0
8162
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8605
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8415
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6076
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4045
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4109
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2550
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 we have to send another system
0
1413
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.