Classes hierarchy?
-
I am trying to come up with “calling scheme” to be able to go "from top to bottom". For example “clear LCD device” via I2C interface and connected to GPIO. The “clear sequence from “top” is to send device specific command - “clear” output binary values of “clear command ” to SDA/SCL interface output binary values to GPIO I have a 3 levels basic / working inheritance scheme - with class representing the device , class representing I2C communication format and class representing the GPIO. I am not sure plain direct inheritance of chain of classes is going to do the job. I think I need to come up with “nesting” scheme instead of just plain direct inheritance chain using only instance of the “top” class. Any suggestions will be appreciated. Something like this, but it looks too scary http://www.linuxtopia.org/online\_books/programming\_books/c++\_practical\_programming/c++\_practical\_programming\_254.html Cheers Vaclav PS Please do not ask for code or "what is it for ? " , this project is under construction and not ready for public scrutiny.
-
I am trying to come up with “calling scheme” to be able to go "from top to bottom". For example “clear LCD device” via I2C interface and connected to GPIO. The “clear sequence from “top” is to send device specific command - “clear” output binary values of “clear command ” to SDA/SCL interface output binary values to GPIO I have a 3 levels basic / working inheritance scheme - with class representing the device , class representing I2C communication format and class representing the GPIO. I am not sure plain direct inheritance of chain of classes is going to do the job. I think I need to come up with “nesting” scheme instead of just plain direct inheritance chain using only instance of the “top” class. Any suggestions will be appreciated. Something like this, but it looks too scary http://www.linuxtopia.org/online\_books/programming\_books/c++\_practical\_programming/c++\_practical\_programming\_254.html Cheers Vaclav PS Please do not ask for code or "what is it for ? " , this project is under construction and not ready for public scrutiny.
I would advise you to try some experiments. It can be very simple. Write a simple class hierarchy with derived classes and have them call a virtual method each of them implements. Within the method, have it output a trace statement (TRACE, printf, cout<<, what ever...) You will see the calling sequence by the order of the output. One thing to be careful of is the order of the calls :
virtual void TestMethod( int n )
{
__super::TestMethod( n+1 ); // call base class
trace( _T( "in TestMethod( %d )\n" ), n );
}// versus : (base class first or base class second)
virtual void TestMethod( int n )
{
trace( _T( "in TestMethod( %d )\n" ), n );
__super::TestMethod( n+1 ); // call base class
}The output will show you which comes first. Implement as many derivation levels as you want, at least three I think. The base class won't have a __super so you will have to comment that off for it. Anyway, I recommend that you try this experiment. It doesn't take long and it is very informative.