What’s the name for a class that has only methods? There are no fields/properties. Just two methods with the ability to parse some file in two ways. I have named the class Parser, but it just doesn’t seem right to have a class do only that. Or?
Should it be in a class ?
EDIT:
Dummy Example
class Parser
{
public int parseMethod1(string file)
{
//parse & return
}
public string[] parseMethod2(string file)
{
//parse & return
}
}
How could I write an interface IParser
which allowed me to have a subclass only implement one of the methods?
8
An object-oriented design may actually be appropriate here, but both your parse methods belong in separate subclasses. You can use generics (type parameters) to achieve this. Something like:
interface IParser<T>
{
public T parse(string);
}
class SomeParser : IParser<int>
{
public int parse(string file)
{
...
}
}
class AnotherParser : IParser<string[]>
{
public string[] parse(string file)
{
...
}
}