我有许多方法的DataAccess类,并访问我使用代码的方法之一
var dataAccess = new DataAccess();
var s = dataAccess.GetDailyStatistic(...);
我想将这些方法组合在非静态类中并像这样访问它们
var dataAccess = new DataAccess();
var s = dataAccess.Statistic.GetDaily(...);
实现这一目标的最佳方法是什么?嵌套类?
DataAccess类结构.
public class DataAccess : DataAccessor
{
public int AddUser(string orderId, string email, string userPassword, string firstName, string lastName,
int membershipId, string store, string country)
public void DeleteBlockedUser(string email)
public void DeleteUserById(int userId)
public MembershipTypes GetMembershipType(int membershipId)
public MembershipTypes GetUserMembershipType(int userId)
public int? GetUserId(string email)
public void UpdateUserExpirationDate(string orderId)
public void UpdateUserCredits(int userId, int membershipId)
public List<UserEntity> LoadUser(string email, string password)
public string GetUserIdFromAuthList(string url)
public UserEntity LoadUserById(int id)
public UserEntity LoadUserByOrderId(string orderId)
public void UpdateUser(int id, string email, string password, string firstName, string lastName)
public void UpdateStatistic(string id, string url, string agent, string ip, string pageTitle)
public List<StatisticEntity> GetStatistic(int userId, DateTime from)
public void GetDailyStatistic(int userId, int days, string url, out string[] arrLabels, out int[] arrValues, out int maxValue)
public void GetWeeklyStatistic(int userId, string url, DateTime from, out string[] arrLabels, out int[] arrValues, out int maxValue)
...skip...
}
最佳答案 为什么不将DataAccess类抽象化,让子类继承它呢?我假设您使用某种数据库连接在DataAccess中拥有所有方法,如果从中继承,您仍然可以在子节点之间共享该连接.你不会再拥有那个单一的构造函数,但是,你可以做类似的事情
var statistic= new Statistic();
var s = statistic.GetDaily(...);
如果您真的喜欢DataAccess名称,请将这些子类放在名称空间DataAccess中,这样看起来就像.
var statistic= new DataAccess.Statistic();
var s = statistic.GetDaily(...);