Types and Interfaces

Interface is just another type of the CLR. Interfaces can have members, with the restriction that an interface cannot have instance fields nor instance methods with implementation.

One can view interfaces as partitioning the set of all possible objects into subsets. Which subsets an object belongs to depends on which interfaces the object’s type has declared compatibility with.

The CLR allows the concrete type to declare the methods interface forced as private provided that one uses some mechanism to indicate that the methods are used to satify the requirements of the interface, which hides the method from the concrete type’s public contract. To access the hided methods, one must use a reference of the interface type, which can acces all interface type declared methods. Consider the following example:

namespace EssentialNet

{

    interface ICustomer

    {

        string GetBirthDay();

    }

}

namespace EssentialNet

{

    public class Customer : ICustomer

    {

        public static string name;

 

        public static string id = "C1";

 

        public static string code = "XIECH2";

 

        public long t1 = DateTime.Now.Ticks;

 

        public long t2 = DateTime.Now.Ticks;

 

        public long t3;

 

         static Customer()

        {

            name = "xiech2";

        }

 

        public Customer()

        {

            t3 = DateTime.Now.Ticks;

        }

 

        #region ICustomer Members

 

        string ICustomer.GetBirthDay()

        {

            return "20100101";

        }

 

        #endregion

    }

}

To access the GetBirthDay method, on must use a reference of type Icustomer.

你可能感兴趣的:(Access)