patterncsharpMinor
Should I split class or keep it all in one?
Viewed 0 times
allkeepsplitoneshouldclass
Problem
Currently, in my project I have one class that is dedicated to the all of the queries for the IBM i and converts it into usable models for my .NET code. There is already 12 methods in this class and there will be many, many more to come. This is for a tool that pulls data from our IBM i and pushes it to our internet database server.
Should I split this class up? Should I make it a partial class and put the code across multiple files? Should I do multiple classes?
Just wondering what the best practice is on something like that.
Currently this is the framework I have in place
```
class IbmIDatabase
{
private DateTime ZERO_DATE = new DateTime(1900, 1, 1, 0, 0, 0);
private string _connString = String.Empty;
SystemCodeRepository scr = new SystemCodeRepository();
///
/// Initializes a new instance of the class.
///
public IbmIDatabase()
{
}
#region System Codes
///
/// Gets all system codes.
///
///
public IEnumerable GetAllSystemCodes()
{
}
#endregion System Codes
#region Citations
///
/// Gets all citations.
///
///
public IEnumerable GetAllCitations()
{
}
#endregion Citations
#region Queue
///
/// Gets the queued records.
///
///
public IEnumerable GetQueuedRecords()
{
}
///
/// Marks the queue as processed.
///
/// The id.
public void MarkQueueAsProcessed(int id)
{
#endregion Queue
#region Utility Bill Customer
///
/// Gets the utility bill customer.
///
/// The customer id.
///
public Customer GetUtilityBillCustomer(int id)
{
}
///
/// Gets the utility bill customer.
///
///
public IQueryable GetUtilityBillCustomer()
{
}
#endregion
#region Utility Bill Details
///
/// Gets the customer history.
///
/// CustomerId
///
public IQueryable GetCustomerHistory(int id)
{
}
Should I split this class up? Should I make it a partial class and put the code across multiple files? Should I do multiple classes?
Just wondering what the best practice is on something like that.
Currently this is the framework I have in place
```
class IbmIDatabase
{
private DateTime ZERO_DATE = new DateTime(1900, 1, 1, 0, 0, 0);
private string _connString = String.Empty;
SystemCodeRepository scr = new SystemCodeRepository();
///
/// Initializes a new instance of the class.
///
public IbmIDatabase()
{
}
#region System Codes
///
/// Gets all system codes.
///
///
public IEnumerable GetAllSystemCodes()
{
}
#endregion System Codes
#region Citations
///
/// Gets all citations.
///
///
public IEnumerable GetAllCitations()
{
}
#endregion Citations
#region Queue
///
/// Gets the queued records.
///
///
public IEnumerable GetQueuedRecords()
{
}
///
/// Marks the queue as processed.
///
/// The id.
public void MarkQueueAsProcessed(int id)
{
#endregion Queue
#region Utility Bill Customer
///
/// Gets the utility bill customer.
///
/// The customer id.
///
public Customer GetUtilityBillCustomer(int id)
{
}
///
/// Gets the utility bill customer.
///
///
public IQueryable GetUtilityBillCustomer()
{
}
#endregion
#region Utility Bill Details
///
/// Gets the customer history.
///
/// CustomerId
///
public IQueryable GetCustomerHistory(int id)
{
}
Solution
This class has a well defined role and by keeping it intact you are satisfying the Single Responsibility Principle. So, I would leave it like that. Perhaps you might want to look into how you could refactor some common code out of each method and into a separate utility class, but that's all.
Context
StackExchange Code Review Q#7683, answer score: 8
Revisions (0)
No revisions yet.