在面向对象的应用程序开发中,类的接口是一个很重要的概念,在.net框架中,.net不仅提供了强大的面向对象的特性,而且它也给我们提供了一系列强大的接口供我们使用,好了我们就来看看petshop3.0中的接口层,从解决方案管理器中的PetShop.IDAL命名空间中,我们可以看到几个接口:IAccountIInventoryIItemIOrderIProductIProfile,我们以IAccount为例:
using System;

 

//References to PetShop specific libraries

//PetShop busines entity library

using PetShop.Model;

 

namespace PetShop.IDAL

{

     /// <summary>

     /// Inteface for the Account DAL

     /// </summary>

     public interface IAccount

     {

         /// <summary>

         /// Authenticate a user

         /// </summary>

         /// <param name="userId">Unique identifier for a user</param>

         /// <param name="password">Password for the user</param>

         /// <returns>Details about the user who has just logged in</returns>

         AccountInfo SignIn(string userId, string password);

 

         /// <summary>

         /// Get a user's address stored in the database

         /// </summary>

         /// <param name="userId">Unique identifier for a user</param>

         /// <returns>Address information</returns>

         AddressInfo GetAddress(string userId);

 

         /// <summary>

         /// Insert an account into the database

         /// </summary>

         /// <param name="account">Account to insert</param>

         void Insert(AccountInfo account);

 

         /// <summary>

         /// Update an account in the database

         /// </summary>

         /// <param name="Account">Account information to update</param>

         void Update(AccountInfo Account);

     }

}

 

这个外露的接口,提供了一系列的操纵帐户信息的相关功能的函数,就像接口的定义那样,我们不必了解这个接口具体是如何实现的,只要我们在业务处理层能够好好使用就行了,按我的理解接口是一系列功能的集合,他把应用程序不同的层次划分得很清楚,这样我们在修改底层的数据库处理过程实现的时候就能够不修改业务处理层和表现层的代码,这也是N层应用程序系统架构模式的好处,层次清晰,不同实现的分离,代码的效率显著提高了,他具有良好的封装特性。