1
\$\begingroup\$

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.

  1. How do I name this? What about GetGetPeakInfoPacket (two gets for a method name)?
  2. Do I break the naming convention here as an exception case and drop one of the gets?
  3. Do I use some other naming convention?

Actually, GetPutPeakInfo sounds a little bit weird too, but at least there's no duplication.

Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Jul 12, 2013 at 7:00
\$\endgroup\$
1
  • \$\begingroup\$ For example, Microsoft doesn't seem to care. "How do we call method, which returns MethodInfo for property getter? PropertyInfo.GetGetMethod(), no problem." In your case, i like Create prefix. But, iguess, its a matter of taste. \$\endgroup\$ Commented Jul 12, 2013 at 10:30

2 Answers 2

6
\$\begingroup\$

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) { ... }
}
answered Jul 12, 2013 at 7:22
\$\endgroup\$
1
  • \$\begingroup\$ Best I could've come up myself so far. :) \$\endgroup\$ Commented Jul 12, 2013 at 7:56
3
\$\begingroup\$

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

answered Jul 12, 2013 at 10:20
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.