Jump to content

Is friendship the proper relationship here?


Recommended Posts

I am not sure the best way to handle state in this scenario so I am looking for insight.

I have some hardware, call it class A. Class A has some state. I have a status byte handler, call it class B. This status byte handler may be different depending on the command I sent, so I have a few Child Class Status Byte handlers. For example, a status byte may be an error we want to acknowledge, ignore, take some action etc depending on the command that was sent. So, I have set this up so class B can have a HandleStatusByte received method which can be overriden when necessary. But, it needs to set the state of class A. It feels like friendship is the proper relationship to allow the status byte handler method to set the state of the hardware class A.

But for some reason I feel like there is a bit of a code smell here. Maybe it's just because I don't use friendship that often and I feel as if I have read some not-so-great things about it in LabVIEW in the past. Maybe I'm wrong?

Anyways, what are other's thoughts?

Link to comment

If you want to make every child of Class B a friend of Class A, that means that A needs to know about every child of B. If you ever need to handle a new status byte, that means you need to create a new child of B, and you also need to update A (to add the new class to its friend list). That's definitely not ideal.

However, if you make only Class B a friend of Class A (such that the child classes don't call A's non-public methods directly), I think it's fine.

Some more details about your system would be helpful for identifying the "best" design. However, here are some thoughts:

  • Do you truly need one child class per status byte? Would you consider putting one big case structure in HandleStatusByte.vi, that uses the byte as the selector?
  • Do you truly need a separate class to handle the status bytes? Would you consider letting Class A do it directly? (I presume Class A is the interface between your controller and the hardware; all commands are sent through Class A and all status bytes are received through Class A)
Edited by JKSH
Link to comment

It would actually be a base handler that all the Status Bytes use, there are just one or two scenarios where it would have to be overriden. 

I could probably do it through class A and maybe I'm overarchitecting it. I am going to review what I have and determine if that's the best way to do it. 

Thanks!

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.