I'm not sure that what I want to do breaks the object-oriented recommendations or not, I will explain what I am doing, and I hope you guys can show me the best way if I am wrong. I tried asking this question before, but I gave a bad example, so I think it just caused more confusion.
So, I have a main class, USBCommunicator. The constructor accepts the product identifier of the type of device you want to talk to. The USBCommunicator class also has a property for a specific serial number for a conversation. USBCommunicator has the OpenConnection and CloseConnection methods that open or close the data stream for transferring data between the USB device and the PC.
To send data over the stream, I want USBCommunicator to be able to instantiate the Report class, set some parameters, such as timeouts, ReportID, etc., and then call the Send () method of the Report class to actually send the data. I do not think that any class other than USBCommunicator should be able to instantiate the Report class. (For example, a boat girl should not create instances of the CarDoor class because the boat cannot have a car door.) Finally, I initially thought that the Report class should have access to the members of the USBCommunicator, but I think it is not. If the USBCommunicator opens the stream, the device that really needs a report is the passed parameter, which is the open stream reference / descriptor. But what form should this stream be,so that it can be transferred by a high-level application? state property? This does not seem right.
So here is what I still have ...
namespace USBTools
{
class HighLevelApplication
{
void main()
{
USBCommunicator myUSB = new USBCommunicator("15B3");
myUSB.SerialNumber = "123ABC";
myUSB.OpenConnection();
myUSB.Report ReportToSend = new myUSB.Report(
ReportToSend.ReportID = 3;
ReportToSend.Timeout = 1000;
ReportToSend.Data = "Send this Data";
ReportToSend.Send();
}
}
class myUSB
{
myUSB(string PID)
{
}
class Report
{
Report(stream StreamToUse)
{
}
Send()
{
}
}
}
}
source
share