Interfaces

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am under the impression that an interface can not have implementation for
any of it's members.

I have been examining the: HttpContext.Current.User object.

The User property of Current is of type IPrincipal. Yet it has a property
called Identity which is of type IIdentity and that has a property called
Name. Now, according to MSDN the HttpContext.Current.User.Identity.Name
property returns the name of the user that is running the web page.

How can it return anything if it has no implementation??? Why make a
property of who's type is an interface? Isn't that fruitless?

Please someone explain, because I'm loosing faith in my understanding of
interfaces.

-Demetri
 
Demetri,

The ^definition^ of the interface can not have any implementation
details associated with it. However, when you return that type (the
interface), there is an implementation behind it which will return a value.
The beauty here is that you can have any number of classes you want handle
the implementation, and you can swap them out however you want, getting
different effects and behavior, without having to change how it is called.

Hope this helps.
 
Yes but in the example I've cited I can not find the implementation. I have a
reflector application that shows me the implementation of classes in the .Net
framework called "Lutz Roeder's .Net Reflector". I can not find where they
are implementing anything.

Got an example of what you speak of that I can see?

Nicholas Paldino said:
Demetri,

The ^definition^ of the interface can not have any implementation
details associated with it. However, when you return that type (the
interface), there is an implementation behind it which will return a value.
The beauty here is that you can have any number of classes you want handle
the implementation, and you can swap them out however you want, getting
different effects and behavior, without having to change how it is called.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Demetri said:
I am under the impression that an interface can not have implementation for
any of it's members.

I have been examining the: HttpContext.Current.User object.

The User property of Current is of type IPrincipal. Yet it has a property
called Identity which is of type IIdentity and that has a property called
Name. Now, according to MSDN the HttpContext.Current.User.Identity.Name
property returns the name of the user that is running the web page.

How can it return anything if it has no implementation??? Why make a
property of who's type is an interface? Isn't that fruitless?

Please someone explain, because I'm loosing faith in my understanding of
interfaces.

-Demetri
 
Demetri said:
Yes but in the example I've cited I can not find the implementation. I
have a
reflector application that shows me the implementation of classes in the
.Net
framework called "Lutz Roeder's .Net Reflector". I can not find where they
are implementing anything.

..Net reflector shows the User property of HttpContext as

public IPrincipal get_User()
{
return this._user;
}

so it is returning the private _user which is of type IPrincipal.

SP
 
Well the GenericPrincipal and GenericIdentity implement them for one. Also the WindowsPrincipal and WindowsIndentity implements them.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Yes but in the example I've cited I can not find the implementation. I have a
reflector application that shows me the implementation of classes in the .Net
framework called "Lutz Roeder's .Net Reflector". I can not find where they
are implementing anything.

Got an example of what you speak of that I can see?

Nicholas Paldino said:
Demetri,

The ^definition^ of the interface can not have any implementation
details associated with it. However, when you return that type (the
interface), there is an implementation behind it which will return a value.
The beauty here is that you can have any number of classes you want handle
the implementation, and you can swap them out however you want, getting
different effects and behavior, without having to change how it is called.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Demetri said:
I am under the impression that an interface can not have implementation for
any of it's members.

I have been examining the: HttpContext.Current.User object.

The User property of Current is of type IPrincipal. Yet it has a property
called Identity which is of type IIdentity and that has a property called
Name. Now, according to MSDN the HttpContext.Current.User.Identity.Name
property returns the name of the user that is running the web page.

How can it return anything if it has no implementation??? Why make a
property of who's type is an interface? Isn't that fruitless?

Please someone explain, because I'm loosing faith in my understanding of
interfaces.

-Demetri

[microsoft.public.dotnet.languages.csharp]
 
Demetri said:
The User property of Current is of type IPrincipal.

Not exactly. The User property returns an object of some class, which
*implements* IPrincipal. Exactly what type that object is should be largely
irrelevant to you, but it really want to know, it's easy enough to find out
(look at it in the debugger, or include
MessageBox.Show(myUser.GetType().ToString());
 
Back
Top