Creating Custom Button Behaviour. Is This Wrong?

bear in mind i started working in 1985. C++ was just coming out in Bell Labs where i worked. i'm not a big fan of classes, as in everything is a class. but i'm a huge fan of object oriented design, which you can do in many languages and may not do correctly using classes.

why should all button functions be in the same class?

what if the functions triggered by different buttons are unrelated and in separate objects

if all the buttons more or less do the same things, then a single generic button function that takes a but-ID as an argument may make sense. that function could just translate the button ID to an ASCII char.

but more likely, if each button requires a unique type of processing, then i think it make much more sense to use an array of function pointers with an argument (e.g. void (*func) (int arg)), even if many of them are to a generic function, hence the arg.

i'll suggest that one reason a button class doesn't make sense is because the action for different buttons may be associated with different objects. (so now you're probably thinking have a register function in a button class with a callback for each button)

in "modular" programming (pre-dated OOD and just a different name for it), each module has a well defined purpose, maximizing "cohesion" and minimizing "coupling", dependencies on other modules (sound familiar)

if the private (i.e. static) and public variables and functions of an object are placed in a single separate files, then the various button functions are spread out.

of course there are many "right" ways to do this.