I am still trying to workout separation of function and how it applies to class creation and namespace inclusion. I have a custom class SoftwareComponent which when presented to the user will most often appear as a ListItem. Is creating a ToListItem method a good idea? I worry because I have now placed a dependency in the class which will require the inclusion of the System.Web.UI.WebControls namespace.
public ListItem ToListItem() { ListItem li = new ListItem(); li.Text = ComponentName + ' (+' + ComponentCost + ')'; li.Selected = Selected; return li; }
My other inclination is to create a ListItem from the SoftwareComponent based on its properties outside of the class itself. Please provide any thoughts on which approach is more appropriate/better.
Could you not provide this additional method as an extension method? It seems to be better suited to being part of a utility class that can be included as a choice by creating a static method that provides this functionality rather than providing it on the main class as a first class method.