wheeler-microfluidics / mr-box-peripheral-board.py

Firmware for MR-Box controller board for various peripherals (e.g., motorized magnet, LED panels, micro pump, temperature/humidity sensor)
MIT License
0 stars 0 forks source link

Inheritance vs composition #2

Open ryanfobel opened 7 years ago

ryanfobel commented 7 years ago

I find the API/structure of this package a bit confusing since the C++ code organized around inheritance while the Python code uses composition. When calling methods from Python, it's difficult to know when to use proxy.zstage_ ... vs proxy.zstage. .... I'm not overly concerned with the structure of this particular project (it works well enough), but I'm more interested in thinking about how to design future projects.

My guess for why you structured it the way you did is that inheritance in the c++ code makes it easy to expose methods via rpc code gen. The problem is that this makes it awkward to access members of the Proxy class from the parent classes (e.g., if you want to access the config member from the ZStage class).

I think I prefer composition if it were possible to use in both c++ and the Python, otherwise I think it would be less confusing if the Python code was also organized as a set of methods on a single base class (e.g., proxy.zstage_state vs proxy.zstage.state. What do you think?

cfobel commented 7 years ago

I have some overarching thoughts on this, but perhaps they are best discussed in person in a design brainstorming session at some point.

On Sun, Aug 6, 2017, 1:40 AM Ryan Fobel notifications@github.com wrote:

I find the API/structure of this package a bit confusing since the C++ code organized around inheritance while the Python code uses composition. When calling methods from Python, it's difficult to know when to use proxy.zstage_ ... vs proxy.zstage. .... I'm not overly concerned with the structure of this particular project (it works well enough), but I'm more interested in thinking about how to design future projects.

My guess for why you structured it the way you did is that inheritance in the c++ code makes it easy to expose methods via rpc code gen. The problem is that this makes it awkward to access members of the Proxy class from the parent classes (e.g., if you want to access the config member from the ZStage class).

I think I prefer composition if it were possible to use in both c++ and the Python, otherwise I think it would be less confusing if the Python code was also organized as a set of methods on a single base class (e.g., proxy.zstage_state vs proxy.zstage.state. What do you think?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/wheeler-microfluidics/mr-box-peripheral-board.py/issues/2, or mute the thread https://github.com/notifications/unsubscribe-auth/AAyQO_YeM5a-66D82WzQ9_Eu-qEE84lkks5sVVHSgaJpZM4OupKQ .