The following are an example of methods supported by a proprietary device:
Monitor
ControlTemp
PutPeakInfo
GetPeakInfo
I have a class that builds the packets for the above corresponding methods:
GetMonitorPacket
GetControlTempPacket
GetPutPeakInfo
Example:
public byte[] GetMonitorPacket(int ddcNum)
{
byte[] monitorPacket = new byte[MONITOR_PACKET_BYTE_COUNT];
Buffer.BlockCopy(START_HEADER_BYTES, 0, monitorPacket, 0, START_HEADER_BYTES.Count());
monitorPacket[2] = (byte) ddcNum;
monitorPacket[3] = 0x01;
byte checksum = 0;
foreach (var b in monitorPacket)
{
checksum = (byte) (((ushort) checksum + (ushort) b) & 0xff);
}
checksum = (byte) (checksum ^ 0x55);
monitorPacket[4] = checksum;
return monitorPacket;
}
All they do is return the bytes in proper format, which then will be sent to the proprietary device via TCP to call the methods. Now I'm screwed on my naming convention for GetPeakInfo
method.
- How do I name this? What about
GetGetPeakInfoPacket
(two gets for a method name)? - Do I break the naming convention here as an exception case and drop one of the gets?
- Do I use some other naming convention?
Actually, GetPutPeakInfo
sounds a little bit weird too, but at least there's no duplication.
2 Answers 2
How about using Generate
as prefix?
GenerateMonitorPacket
GenerateControlTempPacket
GeneratePutPeakInfoPacket
GenerateGetPeakInfoPacket
Alternatively, you can also create a separate class for each type of packet generator. You've only shown the code to create the packet for Monitor
, so I don't know how complex the code for the other packets is, but separating these four methods into their own class might be logical and beneficial in the long run. If you create separate classes, you put the name of the packet (Monitor, ControlTemp, PutPeakInfo and GetPeakInfo) in the class name.
public class MonitorPacketGenerator
{
public byte[] Generate(int ddcNum) { ... }
}
-
\$\begingroup\$ Best I could've come up myself so far. :) \$\endgroup\$Abbas– Abbas2013年07月12日 07:56:46 +00:00Commented Jul 12, 2013 at 7:56
I have a class that builds the packet
Then why don't you call your methods Build*
, e.g. BuildMonitorPacket
?
I think such naming is also clearer, because "build" says more clearly what does the method do, "get" is too general. (For example, it would make sense if a "get" method returned the same result every time, but not so much for a "build" method.)
MethodInfo
for property getter?PropertyInfo.GetGetMethod()
, no problem." In your case, i likeCreate
prefix. But, iguess, its a matter of taste. \$\endgroup\$