Hi team
Say we have a function that run a robot - runRobot(), and it take a robot structure, and this structure contains necessary information for runRobot() to do stuff:
Say I want to add a special skill to this robot, and I define a structure for special skill like this:
And I want to be able to add to my robot by simply adding the new skill to the robot structure without modifying my runRobot() code like this:
Say we have a function that run a robot - runRobot(), and it take a robot structure, and this structure contains necessary information for runRobot() to do stuff:
Code:
typedef struct ROBOT_OBJ{
uint8_t health;
uint8_t attack;
uint8_t block;
}robot_obj_s;
robot_obj_s simple_robot;
runRobot(simple_robot)
Code:
typedef struct SKILL_FLY{
uint8_t max_speed;
uint8_t booster;
uint8_t steering;
...
}skill_fly_s;
Code:
[CODE]typedef struct ROBOT_OBJ{
uint8_t health;
uint8_t attack;
uint8_t block;
skill_fly_s skill_fly; /* added new skill */
}robot_obj_s;
robot_obj_s simple_robot;
/*!
* my runRobot() function can regonizse this new skill
* without me rewritting the runRobot() function
*/
runRobot(simple_robot)