473,795 Members | 2,922 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inheritance and Shared Methods

1. I have a Base class that has a certain amount of functionality.
2. Then I have a CodeSmith generated class that inherits from the Base class
and adds functionality.
3. Since I want to be able to re-generate the classes on level 2 I have a
3rd level that inherits from them and implements specific hand coded
methods.
4. My colleague asked me to create a 4th level class that inherits the 3rd
level class so he can write custom functionality that overrides the "plain"
functionality at all levels above it.

I have 1-3 implemented as Shared methods.
To me, this enables simpler UI code.

For example:
strSQL = Level3ClassName .Select

In this way I do not need to instantiate an instance of the class I just use
the shared methods in levels 1-3.

=============== =============== =============== ==============
My problem (other than being new and not really understanding this well
enough yet <g> )
is I don't know how to implement Level 4 in a way that allows me to use
Shared methods in levels1-3 and yet Override them in Level 4.

Is it not possible?
=============== =============== =============== =============== ==

If I have to change Levels 1-3 what would you recommend?

=============== =============== =============== ===

Sample code:

Level 1
Public MustInherit Class Base

Public Shared Function DoSomething(ByV al Source As String) As String

End Function
=============== =============== =============== ===
Level 2
Public MustInherit Class GeneratedStuff

Inherits Base

Public Shared Function DoSomethingElse (ByVal Source As String) As String

End Function
=============== =============== =============== ===
Level 3
Public MustInherit Class HandCodedStuff

Inherits GeneratedStuff

Public Shared Function IWroteThis(ByVa l Source As String) As String

End Function
=============== =============== =============== ===
Level 4 (implements same functionality as Level 3 but also allows customized
changes by overriding methods or creating new ones that are specific to a
single client. Level 3 functionality is for all clients.)
Public MustInherit Class FinalLevel

Inherits HandCodedStuff

Overrides Function DoSomethingElse (ByVal Source As String) As String

End Function

Thanks for any advice!
--
Joe Fallon


Nov 20 '05
33 3501
I just got back from a business trip and this is the first chance I have had
to look at this thread.

I would like to thank all of you for providing me with so much information.

I won' t be able to test it for a few days but I am leaning towards the use
of Shadows right now.
It may be good enough but I am not 100% sure.

I do have a Singleton class so I am familiar with that concept.
(I use it for Read/Write app settings.)

I am looking for a way to use the Shared methods and still give my co-worker
the ability to get a custom behavior in the 4th level. (We would "never"
call directly into levels 1,2 3.)

I am sure I will be back with more questions!
Thanks again for the spirited discussion.
--
Joe Fallon
"Fergus Cooney" <fi*****@post.c om> wrote in message
news:e0******** ******@TK2MSFTN GP09.phx.gbl...
Hi Joe,

If you want to keep your methods as Shared then you can't use Overrides in Level 4. Overrideable and Overrides are only available with object methods, so that would be goodbye to your Shared..

There is, however, the option of using Shadows. In FinalLevel,
Shadows Function DoSomethingElse (...) As String
will make the name DoSomethingElse available to users of that class.

If you were doing this using object methods and Overrides, you would call the base class method using MyBase.SameMeth od as Scott pointed out.

With Shared methods the equivalent is simply to use the name of the base class.

So you could have:
'Level 2
Public MustInherit Class GeneratedStuff
Inherits Base
Public Shared Function DoSomethingElse (...) As String
End Function
End Class

'Level 4
Public MustInherit Class FinalLevel_Clie nt1
Inherits HandCodedStuff
Shadows Public Shared Function DoSomethingElse (...) As String
GeneratedStuff. DoSomethingElse (...) 'If necessary:
'Do Client1's something else.
End Function
End Class

'Ditto for Client2, etc.

Regards,
Fergus

Nov 20 '05 #31
Initial testing shows that Shadows does what I am looking for!

In my 4th level class I can opt to "do nothing" in which case I get the
standard functions available in the 3 levels above it. But if I want to
replace specific functionality with "custom" code I can use syntax like
this:

Public Shared Shadows Function DoSomething() As String
Return "Custom String"

End Function

I think this will work for me.
So thanks again to all for their input!
--
Joe Fallon

"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I just got back from a business trip and this is the first chance I have had to look at this thread.

I would like to thank all of you for providing me with so much information.
I won' t be able to test it for a few days but I am leaning towards the use of Shadows right now.
It may be good enough but I am not 100% sure.

I do have a Singleton class so I am familiar with that concept.
(I use it for Read/Write app settings.)

I am looking for a way to use the Shared methods and still give my co-worker the ability to get a custom behavior in the 4th level. (We would "never"
call directly into levels 1,2 3.)

I am sure I will be back with more questions!
Thanks again for the spirited discussion.
--
Joe Fallon
"Fergus Cooney" <fi*****@post.c om> wrote in message
news:e0******** ******@TK2MSFTN GP09.phx.gbl...
Hi Joe,

If you want to keep your methods as Shared then you can't use

Overrides in
Level 4. Overrideable and Overrides are only available with object

methods, so
that would be goodbye to your Shared..

There is, however, the option of using Shadows. In FinalLevel,
Shadows Function DoSomethingElse (...) As String
will make the name DoSomethingElse available to users of that class.

If you were doing this using object methods and Overrides, you would

call
the base class method using MyBase.SameMeth od as Scott pointed out.

With Shared methods the equivalent is simply to use the name of the

base
class.

So you could have:
'Level 2
Public MustInherit Class GeneratedStuff
Inherits Base
Public Shared Function DoSomethingElse (...) As String
End Function
End Class

'Level 4
Public MustInherit Class FinalLevel_Clie nt1
Inherits HandCodedStuff
Shadows Public Shared Function DoSomethingElse (...) As String GeneratedStuff. DoSomethingElse (...) 'If necessary:
'Do Client1's something else.
End Function
End Class

'Ditto for Client2, etc.

Regards,
Fergus


Nov 20 '05 #32
;-))
Nov 20 '05 #33
Fergus,

Please see the thread entitled "Ole Container" and if you have input please
help.....

"Fergus Cooney" <fi*****@post.c om> wrote in message
news:OY******** ******@TK2MSFTN GP12.phx.gbl...
;-))

Nov 20 '05 #34

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

Similar topics

20
10087
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in advance for enlightment ... here's the snippet #!/usr/bin/python
3
1703
by: marv | last post by:
If I have abstract base classes like these: //--------- class IBase { public: virtual void Action(void) = 0; };
14
12921
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at all obvious in VBA which lacks inheritance. I'm trying the explanation again now. I often find cases where a limited form of inheritance would eliminate duplication my code that seems impossible to eliminate otherwise. I'm getting very...
5
2050
by: Invalidlastname | last post by:
Hi, I just read the pattern "Design and Implementation Guidelines for Web Clients" from MSDN. Here is my question. In chapter 3, http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/diforwc-ch03.asp , the article mentions using page inheritance to maintain common page layout. We currently use page inheritance approach to segment the function areas. In each function area, there is a base page to provide the common...
10
1250
by: John | last post by:
Hi, How can I achieve that a childs constructor is only callable from it's parent? Must I declare the class Private within A? Thanks in Advance Public MustInherit Class A Protected Sub New()
2
1204
by: rodchar | last post by:
hey all, i have a MustInherit class and a derived class. is it possible to have a shared method in the base class and use it? Note: this is not working for me but just going to explain. i have a base class that has a shared function that returns a connection string for a datasource. is there a way for the derived class to use that? when i try me.connStr it says i have to instantiate it.
5
1096
by: AWesner | last post by:
I've been working on a project to help myself better understand how inherited classes work. I think I've learned more about classes by doing this than any other effort I've made. I've tried to create a simple problem by creating a class named TestThis that inherits System.Windows.Forms.Form and then adding one shared procedure to this. I set the form to inherit TestThis instead and it gets everything plus the one procedure that I've...
6
1887
by: burningodzilla | last post by:
Hi all - I'm preparing to dive in to more complex application development using javascript, and among other things, I'm having a hard time wrapping my head around an issues regarding "inheritance" using the prototype property. I realize there are no classes in JS, that code therefore lives in objects instead of class definitions, and that "inheritance" must be achieved prototypically and not classically. That said, on with the code. Say I...
8
1312
by: tharringtonan | last post by:
I am compiling the following code, main.cpp, as follows: gcc main.cpp I get the following compile error: main.cpp: In function `int main()': main.cpp:28: no matching function for call to `CPolygon::area()' The code is listed below:
0
10439
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
10215
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
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
6783
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
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
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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

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.