why interface methods are public by default

G

Guest

A c# design question - why interface methods are designed to be implicitly
public (that is, no access specifier) - for allowing flexibility to the
classes implementing the interface?
 
A

Alex Meleta

Hi Sameeksha,

Because it's a class contract (for class-external data exchanging, exposing
certain implementation and such) and should be visible. Why do you need the
private methods for it? A (abstract) classes are used to contain public and
hiden implementation (coz they are base for further implementation).

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com



S> A c# design question - why interface methods are designed to be
S> implicitly public (that is, no access specifier) - for allowing
S> flexibility to the classes implementing the interface?
S>
 
M

Michael Nemtsev

Hello Sameeksha,

Such a C# language design, to support only public interfaces.
Albeit in other languages interfaces can be private http://en.wikipedia.org/wiki/Interface_(computer_science)

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

S> A c# design question - why interface methods are designed to be
S> implicitly public (that is, no access specifier) - for allowing
S> flexibility to the classes implementing the interface?
S>
 
J

John Duval

A c# design question - why interface methods are designed to be implicitly
public (that is, no access specifier) - for allowing flexibility to the
classes implementing the interface?

Hi Sameeksha,
If your class implements an interface, you are implicitly agreeing
that your class supports the interface in its entirety. It does not
make sense to implement an interface and then hide some of the members
as "private" for example. Consider the problem from a client's
perspective... if you get an object and you find that it implements a
certain interface, you want to be able to call methods/properties on
that interface without first checking to see if each one is "public".

Hope this helps,
John
 
J

Jon Skeet [C# MVP]

Because it's a class contract (for class-external data exchanging, exposing
certain implementation and such) and should be visible. Why do you need the
private methods for it? A (abstract) classes are used to contain public and
hiden implementation (coz they are base for further implementation).

There are levels between private and public though... it's far from
uncommon to have an internal interface which would be nicely
implemented with internal methods...

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top