Skip to content

GuiEngine: Why not registering the keypad as part of the constructor? #127

@FiveTeethless

Description

@FiveTeethless
          Why not registering the keypad as part of the constructor?

I see the following advantages:

  • The semantic necessity (the engine needs the keypad to operate) would be represented technically.
    The user of the engine can not forget to register the keypad.
  • IKeypad &myKeypad could then be a member of GuiEngine which is initialized by the member initializer list of GuiEngine(). Declaring the functions keypad_read_*() as members of GuiEngine would eliminate the need to check for NULL pointer in those functions. Also because a reference would be used instead of a pointer. Using member functions as callback would require to define a private static member function, which would act as relay and use the callback argument to call the actual member as for example
    reinterpret_cast<GuiEngine *>(indev_drv->disp->driver->user_data)->keypad_read_enter(...)
    
    or (requires to define indev_drv->user_data)
    reinterpret_cast<GuiEngine *>(indev_drv->user_data)->keypad_read_enter(...)
    
    GuiEngine(const Configuration &configuration, TwoWire &i2c, IKeypad &keypad);

Did we already talk about it? I have a vague memory 🤔

Originally posted by @dhebbeker in #123 (comment)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions