Results 1 to 10 of 10

Thread: [RESOLVED] uninitiatable class

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Resolved [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?

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    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?

  3. #3
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: uninitiatable class

    NB - the code you gave above doesn't prevent you from creating a new instance of the class at all.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    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

  5. #5
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    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.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Re: uninitiatable class

    cool, it does makes sense too i guess, to make it protected in the case of someone else extending

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Re: uninitiatable class

    yepp something arnd those lines

  9. #9
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    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?

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Re: [RESOLVED] uninitiatable class

    yepp for others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width