Say we have the following classes:
public class Ticket { public int Id { get; set; } public string Event { get; set; } ... } public class TicketService { public void acceptTicket(Ticket ticket) { ... } ... }
My question is: where is the best way to add static helper methods (which do not require a state like the service class) associated with the ticket object? (Keeping this in mind, this is one object / service among many other objects / services throughout the system).
Now I'm thinking about the following options:
- Create a new TicketHelper class in your own .cs file.
- Create a static helper class directly in the Ticket class
- Create a static helper class directly in the service class
- Just add methods directly to the service class like any other service method
- ... a better solution than these?
For clarity, here I mean for # 2 or # 3.
public class TicketService { public void acceptTicket(Ticket ticket) { ... } ... public static class Helper { public static Dictionary<string, List<Ticket>> groupByName(List<Ticket> tickets) {
In this case, the API may look like this:
Ticket ticket = new Ticket(); List<Ticket> tickets = new List<Tickets>(); TicketService service = new TicketService(); service.acceptTicket(ticket);
source share