Group methods in a class

I have a DataAccess class with many methods and I use code to access one of the methods

var dataAccess = new DataAccess(); var s = dataAccess.GetDailyStatistic(...); 

I would like to group these methods into a non-stationary class and access them as such

 var dataAccess = new DataAccess(); var s = dataAccess.Statistic.GetDaily(...); 

What is the best way to achieve this? Nested classes?

The structure of the DataAccess class.

 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... } 
+4
source share
1 answer

Why not abstract the DataAccess class and inherit its subclasses? I assume that you have all the methods inside DataAccess, using some kind of database connection, if you inherit it, you can still share this connection between the children. You will no longer have this single constructor, but you could do something like

 var statistic= new Statistic(); var s = statistic.GetDaily(...); 

And if you really like the name DataAccess, put these child classes in the DataAccess namespace to make it look.

 var statistic= new DataAccess.Statistic(); var s = statistic.GetDaily(...); 
+2
source

All Articles