-1
public class AStreamManager
{
    public IVehicle Vehicle { get; set; }

    public string AIp { get; set; }
    public int APort { get; set; }

    public delegate NetworkStream ConnectToAStream(string host, int port);

    public AStreamManager(IVehicle vehicle, string IP, int Port)
    {
        Vehicle = vehicle;

        AIp = IP;
        APort = Port;
    }

    public NetworkStream ConnectToVehicleAStream(ConnectToAStream conn)
    {
        return conn(AIp, APort); ;
    }
}

public class BStreamManager
{
    public IVehicle Vehicle { get; set; }

    public string BIp { get; set; }
    public int BPort { get; set; }

    public delegate NetworkStream ConnectToBStream(string host, int port);

    public BStreamManager(IVehicle vehicle, string IP, int Port)
    {
        Vehicle = vehicle;

        BIp = IP;
        BPort = Port;
    }

    public NetworkStream ConnectToVehicleBStream(ConnectToBStream conn)
    {
        return conn(BIp, BPort); ;
    }

}

I have two classes AStreamManager and BStreamManager. As you can see above,there is a member variable Vehicle of type IVehicle which is common across these classes. Does it make sense and can I refactor in such a way that 'IVehicle Vehicle` is moved to a base class?

liv2hak
  • 14,472
  • 53
  • 157
  • 270
  • The classes are identical. Why do you have two of them? You can "refactor" them into a single `StreamManager` class, and then instantiate one for AStream and another for BStream? `var aStream = new StreamManager(); var bStream = new StreamManager;` – Rufus L Aug 02 '17 at 03:50
  • The answer to your question is yes, you can move Vehicle to a base class. Anything else? – John Wu Aug 02 '17 at 03:51

1 Answers1

2

This question seems very hypothetical to me. Looking at your classes, I can't really see a reason for their existence at all. You have AIp and BIp but these are clearly IP addresses, so it makes no sense to have two different properties. I'd simply have a StreamManager class and that's that.

Gregory Higley
  • 15,923
  • 9
  • 67
  • 96