473,472 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

protected interface members

I know this is not supported, but i'm just looking for some reasoning and
perhaps debate.
Is there are reason why this is not supported as in the words of manhy a
French poet "it's doing my head in".

I simply wish to break some concrete (and circular) dependencies into
interface dependences and decouple some of my classes. It is an internal
coupling (almost) as i don't want some of these methods exposed to the
outside world, only to derived classes.

However, it may span assemblies so internal interfaces don't work for me.
Public interfaces of course do the job, but i don't want to expose internals
to consumers of my services.

Basically, i want to create an interface for members that can be inherited
in derived classes. But i can't.

steven :: http://stevenR2.com
Jan 23 '06 #1
8 4321
It sounds like you want an abstract class more than an interface.
There's no reason you can't delcare something 'protected abstract' in
your base class.

Is there a reason you need to have an interface over an abstract class?

HTH
Andy

Jan 23 '06 #2
Andy wrote:
It sounds like you want an abstract class more than an interface.
There's no reason you can't delcare something 'protected abstract' in
your base class.

Is there a reason you need to have an interface over an abstract class?


It will only be a problem in case of multiple inheritance
Jan 23 '06 #3
I am "inheriting" from multiple base classes (i'm not of course, but that's
what i'm going for at the interface level) and so i need to use interfaces
(base entities plus some services interfaces). I do have a base abstract
class, but also some some interfaces that state what derived classes should
implement.

"Andy" <aj********@capcitypress.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
It sounds like you want an abstract class more than an interface.
There's no reason you can't delcare something 'protected abstract' in
your base class.

Is there a reason you need to have an interface over an abstract class?

HTH
Andy

Jan 23 '06 #4
If you're using .Net 2.0, you may be able to take advantage of the
friend assemblies concept.

You can define an interface with scope internal, then define which
assemblies may see the internals of the assembly containing your
interface. Check out the InternalsVisibleTo assembly attribute.

If you're not in .Net 2, I don't think there's anything you can do at
compile time if you want to go down this route. I'd reconsider how the
classes are split between assemblies and the class design itself.

If your classes are so close that they all must implement the same
method, then they are probably very closely related and should be
decoupled. If your classes aren't that closely related, they shouldn't
care if another class implments a method internally or not.

Andy

Jan 23 '06 #5
Opps..

If your classes are so close that they all must implement the same
method, then they are probably very closely related and should be
decoupled.

Should be

If your classes are so close that they all must implement the same
method, then they are probably very closely related and should NOT be
decoupled.

Jan 23 '06 #6
Hi,
The interface is a PUBLIC contract , it's a contract from a type of what it
assure to declare.

From this point of view it's intended to be used from a client perspective.
That's why you cannot declare a protected method, why declare a protected
member in something that is intented to assure the client code what it does
implement?

Now, if you see an interface as a kind of "lite" multiple inheritance, then
it does makes A LOT of sense to allow protected methods, and why not,
private too. in this case it would work as an pure abstract class.
No idea what the consequences this would have though ( I had never thought
about this until now ), once you go down that road you may conclude that is
easier to just implement multiple inheritance.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 23 '06 #7
"Andy" <aj********@capcitypress.com> a écrit dans le message de news:
11*********************@g43g2000cwa.googlegroups.c om...

| You can define an interface with scope internal, then define which
| assemblies may see the internals of the assembly containing your
| interface. Check out the InternalsVisibleTo assembly attribute.

Wonderful, another tidbit I didn't know :-) Thank you.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jan 25 '06 #8
Thanks - decoupled them a bit more and did some extra framework stuff to get
what i needed - kind of.

Sometimes just thinking differently solves the problem, as opposed to my
"there MUST be a way to do this" initial approach :)

Best Wishes,
Steven

http://stevenR2.com

"Andy" <aj********@capcitypress.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Opps..

If your classes are so close that they all must implement the same
method, then they are probably very closely related and should be
decoupled.

Should be

If your classes are so close that they all must implement the same
method, then they are probably very closely related and should NOT be
decoupled.

Jan 25 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: away | last post by:
Why some classes are seen to has their constructors declared as "protected"? Thanks!
28
by: Act | last post by:
Why is it suggested to not define data members as "protected"? Thanks for help!
7
by: Nick Keighley | last post by:
Hi, I'm curious about best practice for protected members. Consider this code fragment:- class Patch { public: Patch (); virtual void draw (Page, int x, int y) = 0;
13
by: Adam H. Peterson | last post by:
I just made an observation and I wondered if it's generally known (or if I'm missing something). My observation is that static protected members are essentially useless, only a hint to the user. ...
6
by: Sgt. Sausage | last post by:
I know it's not possible, but I need a protected internal interface: protected internal interface ISomeInterface{ // yadda yadda yadda } Basically, I need an interface that is completely...
3
by: Jordan Taylor | last post by:
I am confused about protected member functions and objects. Is there any particular advantage of declaring members protected?
12
by: tobias.sturn | last post by:
Hi! My prof told me always to make my members private or protected cause its standard to write setter and getter methodes.. Is that in your opinion correct? Cause I dont see any adventages to...
86
by: jopperdepopper | last post by:
Hi, finally giving php 5 a go, and going over the new approach to classes. Can someone clarify the public, private and protected to me? I quote the php manual: "The visibility of a property or...
6
by: Rick | last post by:
Hi, Can anyone explain to me why the below fails to compile - seeing otherA->f(); as a call to a inaccessible function, while otherB->f(); is ok? It seems you can happily access protected...
3
by: Goyal | last post by:
I am trying to provide interface between C and C++ files. I am providing wrapper classes. Some classes contain protected members. Please suggest me how to use or ignore these protected members of...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.