I have an Item class:
public class Item {
public long Id {get; protected set;}
public string Name {get; protected set;}
}
and now I want to add a function that extracts elements from db according to filters. This should be a static method returning Item []:
public static Item[] GetItems(long? itemId, string itemName) {
//Do Search in the db for items with Id=itemId (in case itemId is not null) and
//with Name=itemName (in case itemName is not null)
return itemsList.ToArray();
}
The question is where to put this method? 1. Should I create a new class for this? What will I call this class? 2. Should I put this method in the Item class?
Another question: In case I want to inherit the Item class. How to force child classes to implement such a GetItems method?
source
share