|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Hiding Default Constructor in VB Express 2005 (Public Not Creatable in VB6)Hello,
I'm looking for a solution to hide the default constructor of a class. In VB6 there was a class type of "Public Not Creatable". I have tried to write the default ctor as friend or private but the compiler adds a default ctor. Actual I use the way to set the default ctor as protected and inside I raise an error if this ctor will be called from an inheriting class. Regards Holger Can't you just mark the class as mustinherit?
i.e. Public MustInherit MyClass() .... End Class Thanks, Seth Rowe Holger Boskugel wrote: Show quoteHide quote > Hello, > > I'm looking for a solution to hide the default constructor of a class. > In VB6 there was a class type of "Public Not Creatable". I have > tried to write the default ctor as friend or private but the compiler > adds a default ctor. Actual I use the way to set the default ctor > as protected and inside I raise an error if this ctor will be called > from an inheriting class. > > > Regards > > Holger Hello Seth,
Show quoteHide quote > > I'm looking for a solution to hide the default constructor of a class. no, I can't in case that I need the class as a Public and will be instanced> > In VB6 there was a class type of "Public Not Creatable". I have > > tried to write the default ctor as friend or private but the compiler > > adds a default ctor. Actual I use the way to set the default ctor > > as protected and inside I raise an error if this ctor will be called > > from an inheriting class. > Can't you just mark the class as mustinherit? > > i.e. > > Public MustInherit MyClass() > ... > End Class through functions in my class library Regards Holger On Nov 14, 6:17 am, "Holger Boskugel" <news.p***@vbwebprofi.de> wrote: Private Sub New()> I'm looking for a solution to hide the default constructor of a class. > In VB6 there was a class type of "Public Not Creatable". I have > tried to write the default ctor as friend or private but the compiler > adds a default ctor. Actual I use the way to set the default ctor > as protected and inside I raise an error if this ctor will be called > from an inheriting class. End Sub Hello Chris,
> > I'm looking for a solution to hide the default constructor of a class. This was what I checked out, but if I reference the library in an> > In VB6 there was a class type of "Public Not Creatable". I have > > tried to write the default ctor as friend or private but the compiler > > adds a default ctor. Actual I use the way to set the default ctor > > as protected and inside I raise an error if this ctor will be called > > from an inheriting class. > Private Sub New() > End Sub other project, class becomes a default public ctor, that is what I don't want. Regards Holger Holger Boskugel wrote:
> > Private Sub New() I'm not sure what you mean here. If you provide a Private Sub New,> > End Sub > > This was what I checked out, but if I reference the library in an > other project, class becomes a default public ctor, that is what > I don't want. > then the class cannot be instantiated directly from another class. The compiler only supplies a default constructor if you don't explicitly declare one. As for inheritance, constructors are not inherited so any derived classes will have to have a private constructor as well if you want to prevent them from being instantiated directly. Hello Chris,
> > > Private Sub New() It's problem of missviewing in the VB.NET Express 2005 IDE. The IDE> > > End Sub > > This was what I checked out, but if I reference the library in an > > other project, class becomes a default public ctor, that is what > > I don't want. > I'm not sure what you mean here. If you provide a Private Sub New, > then the class cannot be instantiated directly from another class. The > compiler only supplies a default constructor if you don't explicitly > declare one. As for inheritance, constructors are not inherited so any > derived classes will have to have a private constructor as well if you > want to prevent them from being instantiated directly. adds allways a Public Default Constructor to my classes in class view, which not exists. I have now tried all kinds of Construtors, the test can be download from this URL : http://www.vbwebprofi.de/public/_news_/VB.NET/Classes/Constructors.zip The result of my test is that Protected Friend Sub New() or Protected Friend Sub New(ByVal in_Parameter As Object) and Friend Sub New() or Friend Sub New(ByVal in_Parameter As Object) fit the former Public Not Creatable in VB6. The both first implementations give programmers the option to inherit my class and call my own constructor with MyBase.New() or MyBase.New(MyParameter). Regards Holger If you add a constructor to your class that has arguments, but don't add
a default (argument-less) constructor, that should hide the default constructor. Public Class SomeClass Public Sub New(ByVal startupInfo As Object) ' ----- Add relevant code here. End Sub End Class Users of SomeClass will now be required to pass an argument to the constructor; just calling "New SomeClass" will not work. ----- Tim Patrick Start-to-Finish Visual Basic 2005 Show quoteHide quote > Hello, > > I'm looking for a solution to hide the default constructor of a class. > In VB6 there was a class type of "Public Not Creatable". I have > tried to write the default ctor as friend or private but the compiler > adds a default ctor. Actual I use the way to set the default ctor > as protected and inside I raise an error if this ctor will be called > from an inheriting class. > Regards > > Holger >
Application performance decrease after deleting rows
Reading value of a bit? how to use variable to refer to a control? Check for Duplicate Appointment Times Cannot open a database from a previous version of your application compare/check character against an array of chars - best practice? Help!! Dynamic Textbox, validation requiredFieldValidator Database & Datagrid issues testing if .NET Framework 2.0 is installed How to bring up a localized form when using application events |
|||||||||||||||||||||||