in reply to How to sub class-es
I think you've got plenty great and actually-useful answers to your question, so I'm gonna overthink it for a sec. You've already figured out that this is a "has-a" situation, so we can lean into that. I submit that you have a "RobotPart" class with the method "Register", meant to return a hash table of functions and names. You have a "RobotDelegate" class that collects all of these parts, registers them all, and houses the combined hash tables.
Unfortunately I have to go and can't type out a demo of what I'm thinking, but hopefully I got the point across. Some things to thing about:
- Do you want parts to call for other parts? (e.g. a hand asking a foot to move to a new place).
- Do you want parts to have their own parts? (e.g. arms have hands, hands have fingers).
- How will you make more complex actions. If, for instance, you want to make a "go get" function that walks to somewhere and then picks something. You might need a "RobotController" class to coordinate between different parts
- Does this body had cardinality? you might need placement on the body
In Section
Seekers of Perl Wisdom