Re: Encapsulation

Tech-Archive recommends: Fix windows errors by optimizing your registry



On Thu, 29 May 2008 02:41:57 -0700, Jon Harrop <jon@xxxxxxxxxxxxxxxxx> wrote:

I believe a lack of multiple inheritance means that cannot work in general
but the idiomatic C# workaround is to use interfaces however C# does not
yet support access modifiers in interfaces. Is that correct?

Technically, yes. But it's not clear what you mean. All interface
members are "public", but interfaces themselves need not be. You can use
the access modifier on the interface itself, nesting the interface as
appropriate, to control access to specific parts of a class.

I see. So you might need many separate interfaces for any given class.

I wouldn't think so. I mean, sure...if you have a very complex set of relationships between implementation and clients, with a variety of clients, each of whom have different accessibility to the implementation, that might require more than one interface. But it seems to me that as you enter that area of complexity, it's time to rethink the overall architecture. That's a _very_ unusual situation and IMHO will practically always be a sign of a larger issue that needs fixing.

That said, I already provided a reply to your most recent problem, showing
you how to solve it. At least for the extant example, it doesn't seem as
though having access modifiers within an interface would be needed or
useful in any case.

Perhaps it would be more concise?

More concise? I don't see how. Do you have an example of a C# syntax that uses access modifiers in an interface as an alternative to my proposal (simply adding the getter to the interface) in order to make a more concise declaration of the code?

Pete
.



Relevant Pages

  • Re: Encapsulation
    ... do that, however, without documenting it prominently. ... I believe a lack of multiple inheritance means that cannot work in general ... You can use the access modifier on the interface itself, nesting the interface as appropriate, to control access to specific parts of a class. ... At least for the extant example, it doesn't seem as though having access modifiers within an interface would be needed or useful in any case. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: iChat, one mans meat ...
    ... IM clients? ... I'd argue that iChat is a better user interface *for their target ... the chat colouring idea predates iChat by quite a long way. ...
    (uk.comp.sys.mac)
  • Re: Holub on getters/setters again
    ... > getter/setter interface, you simply can't implement that solution, so it ... code and how it uses the server methods, rather than focusing on how the ... Especially they might hint to clients implementing operations on ... whenever I modify the implementation of string (for example if I switch ...
    (comp.object)
  • Re: On getters/setters (to Daniel T.)
    ... >> code and how it uses the server methods, ... > might be reasonable to conclude that its clients are working on that data. ... I'm saying that changes to the interface of a class are (or at least ... to server code that would break client code. ...
    (comp.object)
  • Routing between subinterfaces
    ... subinterfaces as the Vlan gateways. ... one interface for all user interaction. ... VLAN 10 clients interface 0/1 ... switchport trunk allowed vlan 20,30 ...
    (comp.dcom.sys.cisco)