DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Wai-Yin Chee Guest

    Equivalent of VB6's Public Not Creatable Class


    What would be equivalent to creating a Public Not Creatable class in VB.NET?


    Wai-Yin Chee
    wchee@sark.com

  2. #2
    Bob Butler Guest

    Re: Equivalent of VB6's Public Not Creatable Class


    "Wai-Yin Chee" <wchee@sark.com> wrote in message
    news:3bb339cf$1@news.devx.com...
    >
    > What would be equivalent to creating a Public Not Creatable class in

    VB.NET?

    A Public Class with no Public constructor




  3. #3
    Rob Teixeira Guest

    Re: Equivalent of VB6's Public Not Creatable Class



    That is certainly the easiest way to implement it.

    However, I believe that in VB6, you got the equivelant of an internal class,
    but only the interface was written to the typelib (not the CoClass entry).
    It was kind of a cludgy way of obscuring the line between class and interface.

    You could also mimic that by creating a public interface and implementing
    that interface in a Friend class. The difference here is that you need to
    know within your application to instantiate a class with a different name
    from the interface. So functionally, a class with only Friend constructors
    is closer.

    -Rob

    "Bob Butler" <butlerbob@earthlink.net> wrote:
    >
    >"Wai-Yin Chee" <wchee@sark.com> wrote in message
    >news:3bb339cf$1@news.devx.com...
    >>
    >> What would be equivalent to creating a Public Not Creatable class in

    >VB.NET?
    >
    >A Public Class with no Public constructor
    >
    >
    >



  4. #4
    Wai-Yin Chee Guest

    Re: Equivalent of VB6's Public Not Creatable Class


    Thanks for the responses! Here's what I have done. I'd like some feedback
    on whether this is considered good practice:

    At this point, I have created the 'Public Not Creatable' class as a Friend
    class (ex: Class B) with functions that are declared Public. Within my application,
    I have a Public Class (ex: Class A) that has a function called GetClassBObject()
    that returns an Object interface which essentially returns the Class B interface.

    From the UI, I am accessing Class B's interface this way:
    Dim objA as New clsA()
    Dim objB as Object

    objB = objA.GetClassBObject()
    'Drawback - intellisense is unavailable
    objB.SomeMethod()

    "Rob Teixeira" <RobTeixeira@@msn.com> wrote:
    >
    >
    >That is certainly the easiest way to implement it.
    >
    >However, I believe that in VB6, you got the equivelant of an internal class,
    >but only the interface was written to the typelib (not the CoClass entry).
    >It was kind of a cludgy way of obscuring the line between class and interface.
    >
    >You could also mimic that by creating a public interface and implementing
    >that interface in a Friend class. The difference here is that you need to
    >know within your application to instantiate a class with a different name
    >from the interface. So functionally, a class with only Friend constructors
    >is closer.
    >
    >-Rob
    >
    >"Bob Butler" <butlerbob@earthlink.net> wrote:
    >>
    >>"Wai-Yin Chee" <wchee@sark.com> wrote in message
    >>news:3bb339cf$1@news.devx.com...
    >>>
    >>> What would be equivalent to creating a Public Not Creatable class in

    >>VB.NET?
    >>
    >>A Public Class with no Public constructor
    >>
    >>
    >>

    >



  5. #5
    Rob Teixeira Guest

    Re: Equivalent of VB6's Public Not Creatable Class



    The easier/more-correct way to do this is:

    Public Class B
    Friend Sub New()
    MyBase.New
    End Sub

    ' other methods/property here
    End Class

    Now, class B can only be created in the original project, but is fully accessable
    in any other other project (without late binding).

    -Rob


    "Wai-Yin Chee" <wchee@sark.com> wrote:
    >
    >Thanks for the responses! Here's what I have done. I'd like some feedback
    >on whether this is considered good practice:
    >
    >At this point, I have created the 'Public Not Creatable' class as a Friend
    >class (ex: Class B) with functions that are declared Public. Within my application,
    >I have a Public Class (ex: Class A) that has a function called GetClassBObject()
    >that returns an Object interface which essentially returns the Class B interface.
    >
    >From the UI, I am accessing Class B's interface this way:
    >Dim objA as New clsA()
    >Dim objB as Object
    >
    >objB = objA.GetClassBObject()
    >'Drawback - intellisense is unavailable
    >objB.SomeMethod()
    >



  6. #6
    Cali LaFollett Guest

    Re: Equivalent of VB6's Public Not Creatable Class

    > Thanks for the responses! Here's what I have done. I'd like some feedback
    > on whether this is considered good practice:
    >
    > At this point, I have created the 'Public Not Creatable' class as a Friend
    > class (ex: Class B) with functions that are declared Public. Within my

    application,
    > I have a Public Class (ex: Class A) that has a function called

    GetClassBObject()
    > that returns an Object interface which essentially returns the Class B

    interface.
    >
    > From the UI, I am accessing Class B's interface this way:
    > Dim objA as New clsA()
    > Dim objB as Object
    >
    > objB = objA.GetClassBObject()
    > 'Drawback - intellisense is unavailable
    > objB.SomeMethod()


    You should still be able to declare "Dim objB as clsB" you just can't go
    "objB = New clsB" or "Dim obj As clsB = New clsB)because the "New" Friend
    constructor method is not visible to your calling code.

    Cal




  7. #7
    Me Guest

    Re: Equivalent of VB6's Public Not Creatable Class


    "Bob Butler" <butlerbob@earthlink.net> wrote:

    >A Public Class with no Public constructor


    Doesn't all classes by default have an public constructor inherited from
    Object?


  8. #8
    Rob Teixeira Guest

    Re: Equivalent of VB6's Public Not Creatable Class



    If you override or shadow the default constructor, you can change the access
    modifier (make it friend, private, etc.).

    -Rob

    "Me" <somewhere@earth.org> wrote:
    >
    >"Bob Butler" <butlerbob@earthlink.net> wrote:
    >
    >>A Public Class with no Public constructor

    >
    >Doesn't all classes by default have an public constructor inherited from
    >Object?
    >



  9. #9
    Bob Butler Guest

    Re: Equivalent of VB6's Public Not Creatable Class


    "Me" <somewhere@earth.org> wrote in message news:3bb36e67$1@news.devx.com...
    >
    > "Bob Butler" <butlerbob@earthlink.net> wrote:
    >
    > >A Public Class with no Public constructor

    >
    > Doesn't all classes by default have an public constructor inherited from
    > Object?


    AFAIK, constructors are not inherited. If you create a class with no
    constructors then the compilers insert a default constructor which may give
    you the same effect but as long as you create at least one Friend
    constructor this does not happen.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links