PC Review


Reply
Thread Tools Rate Thread

access pattern

 
 
Jeff.Boeker@gmail.com
Guest
Posts: n/a
 
      6th Sep 2006
Hello,

I have a group of custom controls and each control is derived from a
base class that performs some standard operations and enforces an
interface by having some abstract methods. Ideally, I don't want my
base class visible outside the assembly; also no instantiation, and no
access by nonderived types. Since C# does not allow multiple
inheritance, I derive my CBaseCtrl from System.Window.Forms.UserControl
and then derive each control from that, e.g. CButtonCtrl : CBaseCtrl.

My initial idea was to make the CBaseCtrl internal abstract and the
CButtonCtrl public but this results in a CS0060 inconsistent
accessibility error. Even if I change the base class to public
abstract so compilation succeeds, when I try to show the designer it
complains that the base class cannot be loaded (because it is
abstract). What is the best way out of this apparent conundrum?

Thanks,

Jeff

 
Reply With Quote
 
 
 
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      6th Sep 2006
Hi,

Define a constructor in CBaseCtrl as private:

private CBaseCtrl(){}

This will prevent the creation of an instance of this class and you do not
have to mark it as abstract.

Ps:
You could declare it as protected if needed.


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I have a group of custom controls and each control is derived from a
> base class that performs some standard operations and enforces an
> interface by having some abstract methods. Ideally, I don't want my
> base class visible outside the assembly; also no instantiation, and no
> access by nonderived types. Since C# does not allow multiple
> inheritance, I derive my CBaseCtrl from System.Window.Forms.UserControl
> and then derive each control from that, e.g. CButtonCtrl : CBaseCtrl.
>
> My initial idea was to make the CBaseCtrl internal abstract and the
> CButtonCtrl public but this results in a CS0060 inconsistent
> accessibility error. Even if I change the base class to public
> abstract so compilation succeeds, when I try to show the designer it
> complains that the base class cannot be loaded (because it is
> abstract). What is the best way out of this apparent conundrum?
>
> Thanks,
>
> Jeff
>



 
Reply With Quote
 
Jeff.Boeker@gmail.com
Guest
Posts: n/a
 
      6th Sep 2006
Hello Ignacio,

Thanks for the quick response. I should have mentioned that I had made
the constructor protected. However, I need to enforce an interface
with some abstract methods within CBaseCtrl so I still need to keep the
class abstract.

Thanks,

Jeff

Ignacio Machin ( .NET/ C# MVP ) wrote:
> Hi,
>
> Define a constructor in CBaseCtrl as private:
>
> private CBaseCtrl(){}
>
> This will prevent the creation of an instance of this class and you do not
> have to mark it as abstract.
>
> Ps:
> You could declare it as protected if needed.
>
>
> --
> --
> Ignacio Machin,
> ignacio.machin AT dot.state.fl.us
> Florida Department Of Transportation
>
>
>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hello,
> >
> > I have a group of custom controls and each control is derived from a
> > base class that performs some standard operations and enforces an
> > interface by having some abstract methods. Ideally, I don't want my
> > base class visible outside the assembly; also no instantiation, and no
> > access by nonderived types. Since C# does not allow multiple
> > inheritance, I derive my CBaseCtrl from System.Window.Forms.UserControl
> > and then derive each control from that, e.g. CButtonCtrl : CBaseCtrl.
> >
> > My initial idea was to make the CBaseCtrl internal abstract and the
> > CButtonCtrl public but this results in a CS0060 inconsistent
> > accessibility error. Even if I change the base class to public
> > abstract so compilation succeeds, when I try to show the designer it
> > complains that the base class cannot be loaded (because it is
> > abstract). What is the best way out of this apparent conundrum?
> >
> > Thanks,
> >
> > Jeff
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
difference between plugin pattern and factory pattern DAXU Microsoft C# .NET 2 26th Feb 2008 02:57 PM
For certain directories, protecting files from direct access that match a naming pattern OR mediating http access through my app Ken Fine Microsoft ASP .NET 1 31st Jul 2007 07:49 AM
database access pattern =?Utf-8?B?VmFsIFA=?= Microsoft Dot NET 4 20th Jan 2006 02:36 PM
Data access pattern =?Utf-8?B?Q2FybG8gRm9saW5p?= Microsoft ADO .NET 7 24th Nov 2004 01:59 PM
Re: the use of .Pattern in access HSalim Microsoft Access VBA Modules 0 24th Jul 2003 02:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:41 PM.