overloaded name + inheritance

J

jrraines

There is an arduino library for LCD displays called LiquidCrystal. At
present the class has the ability to handle either 4 or 8 data pins
and various forms of testing the LCD's busy flag. The initial part of
the declaration looks like this:
class LiquidCrystal : public Print {
public:
LiquidCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);

LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);


LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);

LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, uint8_t en2,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); //4x40 LCD w
2x HD44780 controller chips, 2 enable lines to select between them 4
data pins

LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, uint8_t en2,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, void (*userFunc)
(int8_t chip) ); //4x40 LCD w 2x HD44780 controller chips, 2 enable
lines to select between them 4 data pins

LiquidCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);

LiquidCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3 , void (*userFunc)
(int8_t chip));

The overloaded versions here imply that either 4 or 8 data pins will
be used and all but one implies the specific form of the busy flag
test. Presently each user gets object code that includes both 4 and 8
bit capability and all versions of the busy test. It strikes me that I
could refactor this with a protoclass that would include the common
elements, then create new protoclasses that would handle either 4 or 8
bits and finally create 7 classes that included just the appropriate
busy test and code for 4 or 8 pins. I think each user would save
several hundred bytes by eliminating the unnecessary portions of code.
Some flags and flag testing would also vanish. On a little 8 bit
Arduino, that is a significant benefit. The piece that I'm struggling
with is whether it is possible to do this without changing the
apparent API--can I have 7 versions that have the same overloaded name
and have each of them inherit differently?
 
M

Michael Tsang

There is an arduino library for LCD displays called LiquidCrystal. At
present the class has the ability to handle either 4 or 8 data pins
and various forms of testing the LCD's busy flag. The initial part of
the declaration looks like this:
class LiquidCrystal : public Print {
public:
LiquidCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);

LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);


LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);

LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, uint8_t en2,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); //4x40 LCD w
2x HD44780 controller chips, 2 enable lines to select between them 4
data pins

LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, uint8_t en2,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, void (*userFunc)
(int8_t chip) ); //4x40 LCD w 2x HD44780 controller chips, 2 enable
lines to select between them 4 data pins

LiquidCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);

LiquidCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3 , void (*userFunc)
(int8_t chip));

The overloaded versions here imply that either 4 or 8 data pins will
be used and all but one implies the specific form of the busy flag
test. Presently each user gets object code that includes both 4 and 8
bit capability and all versions of the busy test. It strikes me that I
could refactor this with a protoclass that would include the common
elements, then create new protoclasses that would handle either 4 or 8
bits and finally create 7 classes that included just the appropriate
busy test and code for 4 or 8 pins. I think each user would save
several hundred bytes by eliminating the unnecessary portions of code.
Some flags and flag testing would also vanish. On a little 8 bit
Arduino, that is a significant benefit. The piece that I'm struggling
with is whether it is possible to do this without changing the
apparent API--can I have 7 versions that have the same overloaded name
and have each of them inherit differently?

You are showing the constructors only. Constructors cannot be inherited.
(although you can explicitly inherit them by a using declaration in C++0x)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top