Group methods in class
I have DataAccess class with many methods and to access one of methods I use code
var dataAccess = new DataAccess();
var s = dataAccess.GetDailyStatistic(...);
I would like to group these methods in non static class and access them like that
var dataAccess = new DataAccess();
var s = dataAccess.Statistic.GetDaily(...);
What is the best method to achieve this? Nested classes?
DataAccess class structure.
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(i开发者_如何学Cnt userId, string url, DateTime from, out string[] arrLabels, out int[] arrValues, out int maxValue)
...skip...
}
Why not make the DataAccess class abstract, and have your sub classes inherit from it? I assume you have all the methods inside DataAccess using some sort of database connection, if you inherit from it, you could still share that connection among the children. You would not have that single constructor anymore, but, you would be able to do something like
var statistic= new Statistic();
var s = statistic.GetDaily(...);
And if you really like the DataAccess name, put those child classes in the namespace DataAccess, so it could look like.
var statistic= new DataAccess.Statistic();
var s = statistic.GetDaily(...);
精彩评论