Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What\'s the name for a class that has only methods? There are no fields/properti

ID: 644294 • Letter: W

Question

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?

Explanation / Answer

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)
{
...
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote