473,609 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Shared constructor not called before Shared method

I have a base class with several derived classes (I'm writing in
VB.NET). I want each derived class to have a unique class ID (a
String), and I want the derived classes to inherit from the base
class *Shared* methods which make use of the class ID.

So I gave the base class a classID field, and then I gave the
derived classes Shared constructors, which I used to set the classID
field to the appropriate values for each derived class. But this
doesn't work! In the example below the method

DerivedClass.Pr intClassID()

prints the class ID for the base class, rather than the derived
class. So the Shared constructor for the derived class, which is
needed to properly initialize the inherited Shared methods of that
class, is not getting called.

However if I create an instance (xyz in the example) of the derived
class the Shared constructor *does* get called, even if I do nothing
with the class instance. This just seems wrong. One would expect
that the Shared fields of a class should get initialized before
any class Shared methods get called, and that this initialization
should not depend on the creation of an actual instance of the class.

So what is going on? Is this an outstanding bug, or a misfeature
that people have resigned themselves to living with, or have I
simply misunderstood a feature? And what should I do to get the
result I want? I can Shadow the PrintClassID method, and then it
works as expected. But I don't want to have to Shadow every method
which uses the classID field -- the whole point was that all that
functionality was to be handled entirely by the base class, without
the derived classes needing to know anything abou it.

Any thoughts?

'===== Begin Example =====
Imports System

Class BaseClass
Protected Shared classID As String = "BaseClass! "

Public Shared Sub PrintClassID()
Console.WriteLi ne("classID = " & classID)
End Sub
End Class

Class DerivedClass
Inherits BaseClass

Shared Sub New()
classID = "DerivedCla ss!"
End Sub
End Class
Module TestModule
Public Sub Main()

'Dim xyz As New DerivedClass
DerivedClass.Pr intClassID()

End Sub
End Module
'===== End Example =====
--
John Brock
jb****@panix.co m

Sep 20 '05 #1
10 3549
John,
DerivedClass.P rintClassID()
This simply compiles to a call to BaseClass.Print ClassID, and
DerivedClass never has to be loaded.

And what should I do to get the result I want?


If you want polymorphism you should be using instance members instead
of Shared.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 20 '05 #2
In article <Ox************ **@TK2MSFTNGP09 .phx.gbl>,
Mattias Sjögren <ma************ ********@mvps.o rg> wrote:
John,
DerivedClass. PrintClassID() This simply compiles to a call to BaseClass.Print ClassID, and
DerivedClass never has to be loaded.
But I explicitly asked for it to be loaded! Since these are shared
methods there is no concern about typing, and there is nothing
stopping me from calling BaseClass.Print ClassID at any time, if
that were what I wanted.

On page 181 of Paul Vick's excellent VB.NET book he notes that "the
general rule of thumb is that a the shared constructor will be run
before anything that could depend on it can be accessed". This
led me to believe that .NET would do what seems to me the natural
thing, which is that if a class had a shared constructor, it would
be run to initialize the class before any of the classes' shared
methods were run.
And what should I do to get the result I want?

If you want polymorphism you should be using instance members instead
of Shared.


Well sure, you can *always* use instance members instead of Shared.
So what then is the point of the .NET framework having Shared
members at all? It's because some information really belongs to
the class rather than the instances, and it is convenient to be
able to access that information without having to go to the trouble
of creating an instance. In this case I am going to have to create
actual instances of my derived classes which I am only going to use
to get meta-information about the classes themselves. This is
not hard, but seems kind of silly.

I guess if you can't do it then you can't do it. But I am still
curious whether this is an oversight -- a defect in the language
-- or whether there is perhaps some good reason why what I want to
do would cause problems and *shouldn't* be allowed. Do you have
any idea what the reasoning is, or do you know any web pages where
this is discussed?
--
John Brock
jb****@panix.co m

Sep 21 '05 #3

"John Brock" <> wrote in message news:dg******** **@reader1.pani x.com...
:
: I have a base class with several derived classes (I'm writing in
: VB.NET). I want each derived class to have a unique class ID (a
: String), and I want the derived classes to inherit from the base
: class *Shared* methods which make use of the class ID.
:
: So I gave the base class a classID field, and then I gave the
: derived classes Shared constructors, which I used to set the classID
: field to the appropriate values for each derived class. But this
: doesn't work! In the example below the method
:
: DerivedClass.Pr intClassID()
:
: prints the class ID for the base class, rather than the derived
: class. So the Shared constructor for the derived class, which is
: needed to properly initialize the inherited Shared methods of that
: class, is not getting called.
:
: However if I create an instance (xyz in the example) of the derived
: class the Shared constructor *does* get called, even if I do nothing
: with the class instance. This just seems wrong. One would expect
: that the Shared fields of a class should get initialized before
: any class Shared methods get called, and that this initialization
: should not depend on the creation of an actual instance of the class.
:
: So what is going on? Is this an outstanding bug, or a misfeature
: that people have resigned themselves to living with, or have I
: simply misunderstood a feature? And what should I do to get the
: result I want? I can Shadow the PrintClassID method, and then it
: works as expected. But I don't want to have to Shadow every method
: which uses the classID field -- the whole point was that all that
: functionality was to be handled entirely by the base class, without
: the derived classes needing to know anything abou it.
:
: Any thoughts?
:
: '===== Begin Example =====
: Imports System
:
: Class BaseClass
: Protected Shared classID As String = "BaseClass! "
:
: Public Shared Sub PrintClassID()
: Console.WriteLi ne("classID = " & classID)
: End Sub
: End Class
:
: Class DerivedClass
: Inherits BaseClass
:
: Shared Sub New()
: classID = "DerivedCla ss!"
: End Sub
: End Class
:
:
: Module TestModule
: Public Sub Main()
:
: 'Dim xyz As New DerivedClass
: DerivedClass.Pr intClassID()
:
: End Sub
: End Module
: '===== End Example =====
: --
: John Brock
Note, I believe you should refrain from using your actual email address
in these posts as they can be scanned by bots that seek them out in
order to include in spam lists. I could be mistaken, but I don't think
so. Mask your email address instead (e.g.: jB****@REMOVEpa nix.com or
something along those lines). This should be the case both for your sig
blocks as well as the email address you use in your newreader.
In any event, how about the following?
---------------------------------------
Option Strict

Imports Microsoft.Visua lBasic
Imports System

Public Class Base
Public Overridable ReadOnly Property ClassID As String
Get
Return "Base"
End Get
End Property

Public Overridable Sub PrintClassID()
SharedFunction( ClassID)
End Sub

Protected Shared Sub SharedFunction( ClassID As String)
Console.WriteLI ne(ClassID)
End Sub
End Class

Public Class Derived1 : Inherits Base
Public Overrides ReadOnly Property ClassID As String
Get
Return "Derived1"
End Get
End Property

Public Overrides Sub PrintClassID()
SharedFunction( ClassID)
End Sub
End Class

Public Class Derived2 : Inherits Base
Public Overrides ReadOnly Property ClassID As String
Get
Return "Derived2"
End Get
End Property

Public Overrides Sub PrintClassID()
SharedFunction( ClassID)
End Sub
End Class

Public Module [module]
Public Sub Main
Dim b As New Base
Dim d1 As New Derived1
Dim d2 As New Derived2

b.PrintClassID
d1.PrintClassID
d2.PrintClassID
End Sub
End Module
---------------------------------------
This will generate the following output:
Base
Derived1
Derived2
HTH
Ralf
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.
Sep 21 '05 #4

"_AnonCowar d" <ab*@xyz.com> wrote in message
news:aG******** ************@tw ister.southeast .rr.com...
:
: "John Brock" <> wrote in message
: news:dg******** **@reader1.pani x.com...
: :
: : I have a base class with several derived classes (I'm writing in
: : VB.NET). I want each derived class to have a unique class ID (a
: : String), and I want the derived classes to inherit from the base
: : class *Shared* methods which make use of the class ID.
: :
: : So I gave the base class a classID field, and then I gave the
: : derived classes Shared constructors, which I used to set the classID
: : field to the appropriate values for each derived class. But this
: : doesn't work! In the example below the method
: :
: : DerivedClass.Pr intClassID()
: :
: : prints the class ID for the base class, rather than the derived
: : class. So the Shared constructor for the derived class, which is
: : needed to properly initialize the inherited Shared methods of that
: : class, is not getting called.
: :
: : However if I create an instance (xyz in the example) of the derived
: : class the Shared constructor *does* get called, even if I do nothing
: : with the class instance. This just seems wrong. One would expect
: : that the Shared fields of a class should get initialized before
: : any class Shared methods get called, and that this initialization
: : should not depend on the creation of an actual instance of the
: : class.
: :
: : So what is going on? Is this an outstanding bug, or a misfeature
: : that people have resigned themselves to living with, or have I
: : simply misunderstood a feature? And what should I do to get the
: : result I want? I can Shadow the PrintClassID method, and then it
: : works as expected. But I don't want to have to Shadow every method
: : which uses the classID field -- the whole point was that all that
: : functionality was to be handled entirely by the base class, without
: : the derived classes needing to know anything abou it.
: :
: : Any thoughts?
: :
: : '===== Begin Example =====
: : Imports System
: :
: : Class BaseClass
: : Protected Shared classID As String = "BaseClass! "
: :
: : Public Shared Sub PrintClassID()
: : Console.WriteLi ne("classID = " & classID)
: : End Sub
: : End Class
: :
: : Class DerivedClass
: : Inherits BaseClass
: :
: : Shared Sub New()
: : classID = "DerivedCla ss!"
: : End Sub
: : End Class
: :
: :
: : Module TestModule
: : Public Sub Main()
: :
: : 'Dim xyz As New DerivedClass
: : DerivedClass.Pr intClassID()
: :
: : End Sub
: : End Module
: : '===== End Example =====
: : --
: : John Brock
I just realized there is even a cleaner approach. This will produce the
same result as my previous code:
---------------------------------------
Option Strict

Imports Microsoft.Visua lBasic
Imports System

Public Class Base
Public Overridable ReadOnly Property ClassID As String
Get
Return "Base"
End Get
End Property

Public Overridable Sub PrintClassID()
Console.WriteLI ne(ClassID)
End Sub

End Class

Public Class Derived1 : Inherits Base
Public Overrides ReadOnly Property ClassID As String
Get
Return "Derived1"
End Get
End Property

End Class

Public Class Derived2 : Inherits Base
Public Overrides ReadOnly Property ClassID As String
Get
Return "Derived2"
End Get
End Property

End Class

Public Module [module]
Public Sub Main
Dim b As New Base
Dim d1 As New Derived1
Dim d2 As New Derived2

b.PrintClassID
d1.PrintClassID
d2.PrintClassID
End Sub
End Module
---------------------------------------
Ralf
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.

Sep 21 '05 #5
In article <yq************ ********@twiste r.southeast.rr. com>,
_AnonCoward <ab*@xyz.com> wrote:
[...]
I just realized there is even a cleaner approach. This will produce the
same result as my previous code:
---------------------------------------
Option Strict

Imports Microsoft.Visua lBasic
Imports System

Public Class Base
Public Overridable ReadOnly Property ClassID As String
Get
Return "Base"
End Get
End Property

Public Overridable Sub PrintClassID()
Console.WriteLI ne(ClassID)
End Sub

End Class

Public Class Derived1 : Inherits Base
Public Overrides ReadOnly Property ClassID As String
Get
Return "Derived1"
End Get
End Property

End Class

Public Class Derived2 : Inherits Base
Public Overrides ReadOnly Property ClassID As String
Get
Return "Derived2"
End Get
End Property

End Class

Public Module [module]
Public Sub Main
Dim b As New Base
Dim d1 As New Derived1
Dim d2 As New Derived2

b.PrintClassID
d1.PrintClassID
d2.PrintClassID
End Sub
End Module
---------------------------------------


Actually you missed the point of my question. I was interested in
*Shared* methods, and getting the class to initialize itself via
the Shared constructor without actually having to create any
instances of the class. .NET seems determined to disallow this.
I had already tried using Shared properties, but .NET won't allow
Overrides and Overridable with Shared properties, and using Shadows
on the property in the derived class doesn't fix the problem (i.e.,
the Shared constructor still isn't called).

However I did find a workaround. If I give the derived class an
empty Shared DoNothing method that the base class doesn't have and
then call DerivedClass.Do Nothing this *does* cause the Shared
constructor of DerivedClass to execute, without the expense of
creating a class instance where one isn't needed. It still means
that I have to explicitly initialize the class though, which is
annoying.

More and more this is looking like an easily fixable language design
flaw to me. Can anyone think of a reason why a Shared constructor
*shouldn't* execute if a Shared method is called before a class
has been instantiated? I realize the odds aren't good of anything
coming of it, but is there a place to go to formally bring this
issue to Microsoft's attention?
--
John Brock
jb****@panix.co m

Sep 21 '05 #6

"John Brock" <jb****@panix.c om> wrote in message
news:dg******** **@reader1.pani x.com...
In article <yq************ ********@twiste r.southeast.rr. com>,
_AnonCoward <ab*@xyz.com> wrote:
[Snipped]

Actually you missed the point of my question. I was interested in
*Shared* methods, and getting the class to initialize itself via
the Shared constructor without actually having to create any
instances of the class. .NET seems determined to disallow this.
I had already tried using Shared properties, but .NET won't allow
Overrides and Overridable with Shared properties, and using Shadows
on the property in the derived class doesn't fix the problem (i.e.,
the Shared constructor still isn't called).

However I did find a workaround. If I give the derived class an
empty Shared DoNothing method that the base class doesn't have and
then call DerivedClass.Do Nothing this *does* cause the Shared
constructor of DerivedClass to execute, without the expense of
creating a class instance where one isn't needed. It still means
that I have to explicitly initialize the class though, which is
annoying.

More and more this is looking like an easily fixable language design
flaw to me. Can anyone think of a reason why a Shared constructor
*shouldn't* execute if a Shared method is called before a class
has been instantiated? I realize the odds aren't good of anything
coming of it, but is there a place to go to formally bring this
issue to Microsoft's attention?
--
John Brock
jb****@panix.co m


John,

Your proposed method will not work either; I'll explain further down.
I think the problem is that you are already blinded by frustration.
So lets take a step back and start over.

First, you must Shadow the desired method in your derived class.
This is due to the fact that you want different behaviour and/or results.
The reason your constructor in the Derived class is never executed is
because the Derived class is never used. If you do not Shadow the method of
the Base class, then the compiler has no way of knowing that it is to
execute the method on your Derived class instead of the Base class, so the
Base class is used.

In it's simplest form, you would need something like:
'----------------------------------------
Public Class BaseClass
Public Shared Function ClassID() As String
Return "BaseClass"
End Function
End Class

Public Class DerivedClass : Inherits BaseClass
Public Shared Shadows Function ClassID() As String
Return "DerivedCla ss"
End Function
End Class
'----------------------------------------

There is really no way around it. Since you expect a different return value,
you must provide an implementation in your Derived class.

Now the reason your latest suggested method will still not work is more of a
scoping issue. If the constructor on your Derived class were to actually
run, then you would actually be changing the ClassID variable in your Base
class. This would be bad.
For a working example of what NOT to do, try the following:
'----------------------------------------
Public Class BaseClass
Protected Shared m_ClassID As String = "BaseClass"

Public Shared Function ClassID() As String
Return m_ClassID
End Function
End Class

Public Class DerivedClass : Inherits BaseClass
Public Shared Shadows Function ClassID() As String
Return m_ClassID
End Function

Shared Sub New()
m_ClassID = "DerivedCla ss"
End Sub
End Class
'----------------------------------------

Now look at the results:
'Produces "BaseClass"
Console.WriteLi ne(BaseClass.Cl assID)
'Produces "DerivedCla ss"
Console.WriteLi ne(DerivedClass .ClassID)
'ALSO Produces "DerivedCla ss"
Console.WriteLi ne(BaseClass.Cl assID)

Since the ClassID is only declared in the Base class and is Shared amongst
all derivatives, altering it in any of the classes in the family will alter
the Base class itself.

If you truly desired to use Shared class type variables, then they must be
isolated to each class type. The following is a working example of using a
Shared class type variable along with a Shared constructor:
'----------------------------------------
Public Class BaseClass
Private Shared m_ClassID As String

Public Shared Function ClassID() As String
Return m_ClassID
End Function

Shared Sub New()
m_ClassID = "BaseClass"
End Sub
End Class

Public Class DerivedClass : Inherits BaseClass
Private Shared m_ClassID As String

Public Shared Shadows Function ClassID() As String
Return m_ClassID
End Function

Shared Sub New()
m_ClassID = "DerivedCla ss"
End Sub
End Class
'----------------------------------------

If you try this, you will see that both constructors are called as expected,
and you also get the expected results. The Private declaration provides,
even enforces, the desired level of isolation. But the common theme here is
that you must Shadow the ClassID function in all your Derived classes,
otherwise the method on the Base class will be executed.
Since Shadowing of the method is required regardless, I am partial to the
very first example since it provides the least amount of typing.

Does this help to clear things up a little bit?

Gerald
Sep 21 '05 #7
On 2005-09-21, John Brock <jb****@panix.c om> wrote:

More and more this is looking like an easily fixable language design
flaw to me. Can anyone think of a reason why a Shared constructor
*shouldn't* execute if a Shared method is called before a class
has been instantiated?
This is actually a pretty good question, but the answer might be
complex. And I haven't really thought out all the permutations
involved. The problem with discussing vague language ideas like the
above is that as you try to define the behavior, each decision you make
creates a new complex topic to think through.

First, you really need to understand that what you're trying to do
is generally a considered a bad idea. It's not that anyone "puts
up with this limitation", it's that this situation doesn't usually
come up, because it's just not a good idea.

Next, the implementation is problematic. What you're really asking for
here is for shared methods and fields to participate in inheritance.
This means that each class definition is going to have to carry around
some type of vtable pointing to all shared methods and fields of all
parent classes. Then when you call Derived.SharedM ethod, the compiler
creates a call to Derived.SharedM ethod rather than
BaseClass.Share dMethod, which means that Derived had better have that
definition some place. Derived.Shared is going to have to first run all
shared ctors up the inheritance tree, then send the actual method call
up the tree. That's bloat, performance issues, and I'm sure there's
some multithreading problems here as well (try to define exactly what
behavior you'd want here in a multithreaded environment).

Now, as a side note, notice that in VB.Net you can call shared members
through an instance reference (I think that's evil, but that's how the
language is defined). What's the compiler supposed to do in that case?
Call the declared type shared member, or are these members supposed to
be virtual (which opens another can of worms).

dim a As BaseClass = New Derived()
a.SharedMethod( )
' who gets called?
Then, think about data rather than methods, since it makes no sense for
shared data to work differently. Right now, shared data exists in a
single class, and it's fairly easy to initialize the class definition
when the data is first accessed.

But do what you suggest, and what does that data look like in memory?
Now data is going to have to act like some kind of virtual method, since
an access to data through a Derived class must somehow redirect the
access to the base class (after tree initialization) .
I realize the odds aren't good of anything
coming of it, but is there a place to go to formally bring this
issue to Microsoft's attention?


I'm sure there's a place, but keep in mind that very smart people have
thought about this stuff a long, long time.

Sep 21 '05 #8
In article <e8************ **@TK2MSFTNGP12 .phx.gbl>,
Gerald Hernandez <Cablewizard@sp *********@Yahoo .com> wrote:
Does this help to clear things up a little bit?


Yes, and thanks. I still think it makes logical sense for the
Shared constructor of a class to get triggered if a Shared method
of that class is invoked, but in fact -- for the reason you pointed
out, i.e., that there is only one classID variable, and the last
class to set it would "win" -- I would still have run into trouble
just a little way up the road. I basically wanted my base class
to do work using fields defined in my derived classes, and even
with instance methods you can't do that. So even though my idea
still seems logical to me I no longer have any examples of cases
where it would actually be useful, so maybe it is just not worth
the bother.
--
John Brock
jb****@panix.co m

Sep 22 '05 #9
In article <sl************ ******@localhos t.localdomain>,
david <da***@woofix.l ocal.dom> wrote:
On 2005-09-21, John Brock <jb****@panix.c om> wrote:

More and more this is looking like an easily fixable language design
flaw to me. Can anyone think of a reason why a Shared constructor
*shouldn't* execute if a Shared method is called before a class
has been instantiated?
This is actually a pretty good question, but the answer might be
complex. And I haven't really thought out all the permutations
involved. The problem with discussing vague language ideas like the
above is that as you try to define the behavior, each decision you make
creates a new complex topic to think through.

First, you really need to understand that what you're trying to do
is generally a considered a bad idea. It's not that anyone "puts
up with this limitation", it's that this situation doesn't usually
come up, because it's just not a good idea.

Next, the implementation is problematic. What you're really asking for
here is for shared methods and fields to participate in inheritance.
This means that each class definition is going to have to carry around
some type of vtable pointing to all shared methods and fields of all
parent classes. Then when you call Derived.SharedM ethod, the compiler
creates a call to Derived.SharedM ethod rather than
BaseClass.Shar edMethod, which means that Derived had better have that
definition some place. Derived.Shared is going to have to first run all
shared ctors up the inheritance tree, then send the actual method call
up the tree. That's bloat, performance issues, and I'm sure there's
some multithreading problems here as well (try to define exactly what
behavior you'd want here in a multithreaded environment).

Now, as a side note, notice that in VB.Net you can call shared members
through an instance reference (I think that's evil, but that's how the
language is defined). What's the compiler supposed to do in that case?
Call the declared type shared member, or are these members supposed to
be virtual (which opens another can of worms).

dim a As BaseClass = New Derived()
a.SharedMethod ()
' who gets called?
Then, think about data rather than methods, since it makes no sense for
shared data to work differently. Right now, shared data exists in a
single class, and it's fairly easy to initialize the class definition
when the data is first accessed.

But do what you suggest, and what does that data look like in memory?
Now data is going to have to act like some kind of virtual method, since
an access to data through a Derived class must somehow redirect the
access to the base class (after tree initialization) .
I realize the odds aren't good of anything
coming of it, but is there a place to go to formally bring this
issue to Microsoft's attention?


I'm sure there's a place, but keep in mind that very smart people have
thought about this stuff a long, long time.


It really doesn't seem all that messy to me. First of all, most
classes don't even have Shared constructors, so most of the time
nothing different would happen. It's true that every shared method
would now have to test a flag somewhere to see whether its class
had been initialized, but how expensive can that be, given everything
else that is going on? Calling a chain of Shared constructors
would be a one time thing, so that wouldn't add any real cost
either. And you would *never* have to call a Shared constructor
when an instance calls a Shared function, because the appropriate
Shared constructor was already called the first time that class
was instantiated. So what am I missing? (OK, threads). It just
seems logical to me that when you explicitly call
MyDerivedClass. SomeSharedClass -- as opposed to calling
MyBaseClass.Som eSharedClass (which you can always do if that is
what you want) -- that the MyDerivedClass Shared constructor ought
to be invoked.

That said, I have to admit that what I was trying to do was in fact
a bad idea, so I can no longer claim to have been victimized by
bad design, and I'm more open to the possibility that maybe this
is *always* a bad idea. :-/
--
John Brock
jb****@panix.co m

Sep 22 '05 #10

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

Similar topics

3
4553
by: Jun | last post by:
I have following script <script> var Animal = function(name){ this.name = name; } Animal.prototype.eat = function (food) {
0
1164
by: CarlT | last post by:
Is there some reason the exceptions in a class with a shared constructor will not bubble up the call stack? I have a class with a shared constructor which calls a shared method Requery() which initializes the class's shared properties. When an exception occurs in the Requery method I want to let it bubble up so I can handle it elsewhere, but it seems the error will not bubble up. The procedure (outside of this class) that first...
10
2240
by: linkspeed | last post by:
Following texts are from C# spec. The optional constructor-initializer specifies another instance constructor to invoke before executing the statements given in the constructor-body of this instance constructor. This is described further in Section 10.10.1. So this means:
14
6299
by: Joe Fallon | last post by:
I am trying to build a Data Access Layer for a SQL Server back end. My class has a number of methods in it. The constructor takes a connection string. I currently have to instantiate an object in order to use one of my methods. So I end up doing this quite a lot in my app. If I change all of the methods to be Shared does that mean I can just use them without instantiaing an instance of my DAL class?
5
11585
by: Erik Cruz | last post by:
Hello! I have read some threads discussing the fact that a module is in reality a shared class. If I try to create a Public Shared Class in vb.net I receive a compile error. Why? If I can't explicitly create a shared class, how does vb.net creates it? TIA, Erik Cruz
10
2273
by: John Brock | last post by:
I have a base class with several derived classes (I'm writing in VB.NET). I want each derived class to have a unique class ID (a String), and I want the derived classes to inherit from the base class *Shared* methods which make use of the class ID. So I gave the base class a classID field, and then I gave the derived classes Shared constructors, which I used to set the classID field to the appropriate values for each derived class. But...
26
2133
by: Patient Guy | last post by:
The code below shows the familiar way of restricting a function to be a method of a constructed object: function aConstructor(arg) { if (typeof(arg) == "undefined") return (null); this.property1 = arg; this.property2 = aConstantDefinedGlobally; this.method1 = function (anArg) {
74
15941
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the creation of this implicit default constructor, to force the creation of a struct via my constructor only? Zytan
0
8139
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
8091
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
8579
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
8555
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...
0
8408
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...
0
4032
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
4098
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1403
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.