Performing various Wireshark services I am building an application that opens Wireshark services (Wireshark has several services) in order to to different things on Wireshark files like edit, change format, statistics, etc. Each option usually uses a different service, so I want to build my classes with inheritance.

I was wondering if what I want to do is appropriate.

Main class WiresharkServices with the following members and methods:

public class WiresharkProcesses
{
    protected string _filePath; //the file path who send to Wiresahrk process
    protected string _capinfos;
    protected string _dumpcap;
    protected string _editcap;
    protected string _mergecap;
    protected string _rawshark;
    protected string _text2pcap;
    protected string _tshark;
    protected string _wireshark;

    public void initializeServices()
    {
        if (Directory.Exists(@"C:\Program Files (x86)\Wireshark"))
        {
            _capinfos = @"C:\Program Files (x86)\Wireshark\_capinfos.exe";
            _dumpcap = @"C:\Program Files (x86)\Wireshark\_dumpcap.exe";
            _editcap = @"C:\Program Files (x86)\Wireshark\editcap.exe";
            _mergecap = @"C:\Program Files (x86)\Wireshark\_mergecap.exe";
            _rawshark = @"C:\Program Files (x86)\Wireshark\_rawshark.exe";
            _text2pcap = @"C:\Program Files (x86)\Wireshark\_text2pcap.exe";
            _tshark = @"C:\Program Files (x86)\Wireshark\_tshark.exe";
            _wireshark = @"C:\Program Files (x86)\Wireshark\_wireshark.exe";
        }
        else if (Directory.Exists(@"C:\Program Files\Wireshark"))
        {
            _capinfos = @"C:\Program File)\Wireshark\_capinfos.exe";
            _dumpcap = @"C:\Program Files\Wireshark\_dumpcap.exe";
            _editcap = @"C:\Program Files\Wireshark\editcap.exe";
            _mergecap = @"C:\Program Files\Wireshark\_mergecap.exe";
            _rawshark = @"C:\Program Files\Wireshark\_rawshark.exe";
            _text2pcap = @"C:\Program Files\Wireshark\_text2pcap.exe";
            _tshark = @"C:\Program Files\Wireshark\_tshark.exe";
            _wireshark = @"C:\Program Files\Wireshark\_wireshark.exe";
        }
    }
}


When the application is running, I am of course checking if Wireshark is installed on the machine. If not, I throw an exception:

WiresharkServices wservices = new WiresharkServices();
wservices .initializeServices();


and in each class its own methods.

Child class example which receives a file path to convert it to another Wireshark format:

public class Editcap : WiresharkProcesses
{
    private string _newFileName;

    public void startProcess(string filePath)
    {
        FileInfo file = new FileInfo(filePath);
        _newFileName = file.FullName.Replace(file.Extension, "_new") + ".pcap";
        ProcessStartInfo editcapProcess = new ProcessStartInfo(string.Format("\"{0}\"", _editcap))
        {
            Arguments = string.Format("{2}{0}{2} -F libpcap {2}{1}{2}", file.FullName, _newFileName, "\""),
            WindowStyle = ProcessWindowStyle.Hidden,
            RedirectStandardOutput = true,
            RedirectStandardError = true,
            CreateNoWindow = true,
            UseShellExecute = false,
            ErrorDialog = false
        };

        using (Process editcap = Process.Start(editcapProcess))
        {
            editcap.WaitForExit();
        }
    }

    public string getNewFileName()
    {
        return _newFileName;
    }
}
The only thing you are getting out of this inheritance is which directory should be used to access the executable. And you are only using that to define a number of (what should be constant) strings. The fact that you have an error in your value for _capinfos in the seconds case should be an indication that this is not the best way to perform this action.

To accomplish the task of initializing the strings, I would instead do something like this.

public void initializeCommands(String path) {
    _capinfos = path + "_capinfos.exe";
    _dumpcap = path + "_dumpcap.exe";
    _editcap = path + "editcap.exe";
    _mergecap = path + "_mergecap.exe";
    _rawshark = path + "_rawshark.exe";
    _text2pcap = path + "_text2pcap.exe";
    _tshark = path + "_tshark.exe";
    _wireshark = path + "_wireshark.exe";
}


You can wrap this in something that determines the path or even support non-standard paths.

But what this really comes down to is that you are using inheritance just so you have easy access to some constants you might want to use. You are not defining any methods that would specify actual code used between multiple classes that execute Wireshark processes. If Editcap were passed in the path to the executable, it would no longer have a need to the parent class. If the coupling is this loose, inheritance is generally not the best idea.