|
-
Jan 3rd, 2010, 09:48 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] uninitiatable class
ive got a class that doesn't want to be initiated. that means trying New MyClass should be prohibited
currently im doing this which works:
Code:
Private Sub New
End Sub
but is this the "right" approach?
-
Jan 3rd, 2010, 09:59 AM
#2
Re: uninitiatable class
Are you trying to create a singleton class, or do you want a class than can only be inherited (MustInherit) or something else entirely?
-
Jan 3rd, 2010, 10:03 AM
#3
Re: uninitiatable class
NB - the code you gave above doesn't prevent you from creating a new instance of the class at all.
-
Jan 3rd, 2010, 10:16 AM
#4
Thread Starter
Hyperactive Member
Re: uninitiatable class
im just using it to store info, i think u can call it a singleton it doesn't have to be inherited.
why doesn't the private new stop an initiation?
i tot it worked, i tried to initiate one and it says i have access restriction
-
Jan 3rd, 2010, 10:21 AM
#5
Re: uninitiatable class
Sorry my mistake - I misread your code.
There are a few ways of creating singletons in vb.net. This one seems to be the most common though.
-
Jan 3rd, 2010, 10:46 AM
#6
Thread Starter
Hyperactive Member
Re: uninitiatable class
cool, it does makes sense too i guess, to make it protected in the case of someone else extending
-
Jan 3rd, 2010, 11:44 AM
#7
Re: uninitiatable class
I think what the OP is looking for is either a shared class that can just be used w/o instanciating it... or to have a private constructor, with a shared factory method that will return a new instance of the class.
-tg
-
Jan 3rd, 2010, 04:18 PM
#8
Thread Starter
Hyperactive Member
Re: uninitiatable class
yepp something arnd those lines
-
Jan 3rd, 2010, 04:33 PM
#9
Re: uninitiatable class
It would help if you explained exactly what you are trying to do.
Are you providing a class for other people to use or is this just for you?
-
Jan 4th, 2010, 02:26 AM
#10
Thread Starter
Hyperactive Member
Re: [RESOLVED] uninitiatable class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|