473,785 Members | 2,498 Online
Bytes | Software Development & Data Engineering Community
+ 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 4346
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********@cap citypress.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.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 InternalsVisibl eTo 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********@cap citypress.com> a écrit dans le message de news:
11************* ********@g43g20 00...legro ups.com...

| 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 InternalsVisibl eTo 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********@cap citypress.com> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.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
2210
by: away | last post by:
Why some classes are seen to has their constructors declared as "protected"? Thanks!
28
3429
by: Act | last post by:
Why is it suggested to not define data members as "protected"? Thanks for help!
7
1797
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
7735
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. They don't actually protect any encapsulation or anything, and for all the actual protection they offer, they might as well be public. For example: class B { protected:
6
12001
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 accessable from within the assembly (internal), but is not valid outside
3
6726
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
2137
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 write a member of a class private if there are no side effects in changing the variable. I think you only have to write more (the getter and setters) the code gets bigger... Thanks very much!
86
4655
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 method can be defined by prefixing the declaration with the keywords: public, protected or private. Public declared items can be accessed everywhere."
6
4140
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 functions of another (same type) - but not via a base class pointer.... I've checked the FAQs, Meyers etc but nothing obvious I can find explains it.
3
1498
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 the core classes in wrapper classes. I used "typedef struct" for the classes which had only public members. But now I m facing problem with classes having protected members also.
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10341
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10095
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9954
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.