// Properties
public virtual string Description { get; }
public virtual string Name { get; }
// Fields
private string _Description;
private bool _Initialized;
private string _name;
}
ProviderBase的派生类较多,包括有System.Configuration.ProtectedConfigurationProvider、System.Configuration.SettingProvider、System.Web.Security.RoleProvider、System.Web.Security.MembershipProvider等,不过这些派生子类都是抽象类,它们又自有各自的继承体系,且同时具备了Strategy模式的特征。以RoleProvider为例,首先,我们看看RoleProvider在.Net Framework中的定义:
public abstract class RoleProvider : ProviderBase
{
// Methods
protected RoleProvider();
public abstract void AddUsersToRoles(string[] usernames, string[] roleNames);
public abstract void CreateRole(string roleName);
public abstract bool DeleteRole(string roleName, bool throwOnPopulatedRole);
public abstract string[] FindUsersInRole(string roleName, string usernameToMatch);
public abstract string[] GetAllRoles();
public abstract string[] GetRolesForUser(string username);
public abstract string[] GetUsersInRole(string roleName);
public abstract bool IsUserInRole(string username, string roleName);
public abstract void RemoveUsersFromRoles(string[] usernames, string[] roleNames);
public abstract bool RoleExists(string roleName);
// Properties
public abstract string ApplicationName { get; set; }
}
在RoleProvider抽象类中,没有具体的实现,均为抽象方法,此时的抽象类其实已与接口无异(注:事实上,在WebLogic中,在对角色管理的API中,就将RoleProvider定义为接口)。为了便于理解这里的设计思想,我们对RoleProvider类进行简化,仅关注该类的CreateRole()抽象方法。
实现RoleProvider抽象类的类型比较多,例如AuthorizationStoreRoleProvider、SqlRoleProvider、WindowsTokenRoleProvider等等。因此,最后的实现类图应该如下:

子类均重写了父类RoleProvider的抽象方法,例如SqlRoleProvider:

