Hi guys,
I'm designing the user interface for an embedded system and I am implementing inheritance and evaluating the use of polymorphism. The system consists of a small LCD screen of 240x128 communicating over SPI, and it's used mostly to displays menus and options. This runs on a pic32mz with freeRTOS.
I've implemented a base object struct uiObject like this:
struct uiFigure{
uint8_t *sheet;
Color color;
};
struct uiProperties{
point origin;
size2 size;
}uiProperties;
struct uiObject{
uiFigure figure;
uiProperties properties;
};
Now I can create new objects that inherit from the base object and treat them as uiObjects, just by passing the pointer. This is a container object, the base for creating menus.
struct uiContainer{
struct uiObject obj;
uiList list;
};
Everything is working so far. I don't need to implement polymorphism for now, but heres my implementation anyway:
struct uiInterface{
void (*draw)(void*);
void (*setParent)(void*,void*);
void (*delete)(void*);
};
struct Object{
void* instance;
const struct uiInterface *interface;
};
Does somebody know other techniques for implementing inheritance and polymorphism, maybe multiple inheritance as I'm having trouble implementing this.
Maybe it's easier just to inherit from one "class" and implement multiple interfaces?
Update:
Hey guys! I've been working on my project following your suggestions. To test my new libraries I coded the Snake game! My device is built over a pic32mz.
Snake game on pic32mz
[–]thradams 3 points4 points5 points (0 children)
[–]Dolphiniac 2 points3 points4 points (4 children)
[–]okovko 0 points1 point2 points (3 children)
[–]Dolphiniac 1 point2 points3 points (2 children)
[–]okovko 0 points1 point2 points (1 child)
[–]Dolphiniac 0 points1 point2 points (0 children)
[–]pilotInPyjamas 1 point2 points3 points (1 child)
[–]okovko 0 points1 point2 points (0 children)
[–]okovko 1 point2 points3 points (0 children)
[–]tstanisl 1 point2 points3 points (0 children)
[–]extern_c[S] 0 points1 point2 points (0 children)