Interface as a field

  • Thread starter Thread starter AMP
  • Start date Start date
A

AMP

Hello,
This looks like an interface as a field or property:
public class AccountController : Controller
{

public IFormsAuthenticationService FormsService { get; set; }
public IMembershipService MembershipService { get; set; }

protected override void Initialize(RequestContext
requestContext)................


What am I missing?
 
This looks like an interface as a field or property:
public class AccountController : Controller
{

public IFormsAuthenticationService FormsService { get; set; }
public IMembershipService MembershipService { get; set; }

protected override void Initialize(RequestContext
requestContext)................

What am I missing?

A question maybe?

:-)

There is nothing wrong by having a property of a type that
is an interface.

Arne
 
A question maybe?

:-)

There is nothing wrong by having a property of a type that
is an interface.

Arne

Thanks Arne, but where can I find some MSDN documentation for this, I
havent seen it before?
 
Thanks Arne, but where can I find some MSDN documentation for this, I
havent seen it before?

The docs say that it can be of a type. An interface is a type. Most
likely noone considered it necessary to say that type includes
interfaces.

Arne
 
Thanks Arne, but where can I find some MSDN documentation for this, I
havent seen it before?

All it means is that any object implementing the IMembershipServices
interface, can be assigned to the FormsService property. The class
AccountController doesn't care about the property beyond the interface,
so it's more flexible about the objects you can pass to it.
 
Arne said:
The docs say that it can be of a type. An interface is a type. Most
likely noone considered it necessary to say that type includes
interfaces.

Following up on what Arne said, the point is that the method invoking
one of these property expects to receive an object of some class that
implements the interface. It doesn't need to know what the class is--it
only needs to know that it can call the class's implementation of the
interface's methods and properties and so on. Likewise, a method that
sets the property can set it to an object of any class that implements
the interface--it doesn't matter which one.
 
Back
Top