Suppose I am developing a robot that can grab a variety of tools and use them. I would create a Robot class that has a Pickup method to select the tools I wanted to use. For each tool, I would create a class for it, say, a class of Knife, which has a Cut method. After calling the Pickup method on Robot, now I want to say that my robot is cutting. So, for the concept of OOP, should I tell the robot, not the knife? And the Cut method on the knife, so how can I call this? I need to implement some UseToolCurrentlyHeld()
on Robot to distribute my commands on Knife. Or I just directly call the knife (which my robot holds) directly using this: myrobot.ToolCurrentlyInHand.Cut()
It seems strange to me that the parent method should have EVERYTHING to take care of the classes that they contain. Now I have repeating methods, for example, the Cut()
Knife, and now the Robot should have UseCutOnKnife()
only to call Cut()
on the Knife, because OOP's good practice is to abstract the Knife and make it feel, what Robot orders without worrying about inside information such as a knife.
Another question, if I compose music, I would create the Music
class, which contains many Measure
classes to store information about the note. In one dimension, there can be many Note
classes inside it; the Note class will have information such as to what extent this note is located, or how long this note plays. Now I want to add one note to measure 45, placed approximately in the middle of the measure. To create a measure, do I have to call CreateMeasure(45)
in the Music section and then call CreateNote(0.5f)
in the Measurement field? Is the creation method on the parent element? And if now I want to change this note by 0.25 per measure, then I am responsible for changing the method. Note: is it a Note
class or a Measure
class? Or should I implement a method for changing notes in the top-most Music
class?
This is an overview of my classes:
class Music { List<Measure> measures = new List<Measure>();
How is the Music class now on top of everything I now need to pass everything through Music? And bind a method to finally name the innermost class?
source share