Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8090533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:45:18+00:00 2026-06-05T19:45:18+00:00

Suppose I’m designing a robot that can pickup various tools and use them. I

  • 0

Suppose I’m designing a robot that can pickup various tools and use them.
I would create a Robot class which has Pickup method to pick the tools I wanted to use.
For each tools I would create a class for it, say, Knife class which has Cut method.
After invoking a Pickup method on Robot now I want to tell my robot to cut. So for OOP concept I have to tell the robot, not knife? And the Cut method is on Knife so how can I invoke that? I have to implement some kind of UseToolCurrentlyHeld() on Robot to propagate my commands to Knife. Or I just directly call the knife (that my robot hold) directly using this: myrobot.ToolCurrentlyInHand.Cut()

I feel it’s weird that a parent method must have EVERYTHING to take care of classes they contain. Now I have duplicate methods, like the Knife has Cut() and now Robot must have UseCutOnKnife() only to invoke Cut() on Knife because good OOP practice is to abstract the Knife out and make it feel like ordering a Robot without worrying about internal information like Knife.

Another question, if I composing a music I would create Music class which contains many Measure class to store note information. In one Measure there can be many Note class inside it which Note class will have information like, where in the measure does this note reside, or how long that note plays. Now I want to add one note on measure 45 placed on about middle of the measure. To create the Measure I have to call CreateMeasure(45) on Music and then call CreateNote(0.5f) on Measure? The method to create is on the parent like that? And if now I want to change that note to be at 0.25 on the measure instead, the one responsible to have method to change Note is the Note class itself or Measure class? Or I must implement the method to change notes on the topmost Music class?

This is overview of my classes :

class Music
{
     List<Measure> measures = new List<Measure>();

     //methods...
}

class Measure
{
     int measureNumber;
     List<Note> notes = new List<Note>();

     //methods...
}

class Note
{
     float positionInMeasure; //from 0 to 1
}

As now the Music class is on top of everything I now have to issue everything through Music? And chaining the method to finally call the innermost class?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:45:20+00:00Added an answer on June 5, 2026 at 7:45 pm

    What you need here is a common interface that all the tools implement.

    E.g.:

    interface ITool {
        void Use();
    }
    

    Now the knife can implement that interface:

    class Knife : ITool {
        public void Use() {
            //do the cutting logic
        }
    }
    

    Now you would use the tool through the ITool interface on the robot, not knowing what tool it is:

    class Robot {
        private ITool currentTool = null;
    
        public void Pickup(ITool tool)
        {
            currentTool = tool;
        }
    
        public void UseTool() {
            currentTool.Use();
        }
    } 
    

    And you can invoke Pickup like that:

     Robot robot = new Robot();
     robot.Pickup(new Knife());
     robot.UseTool();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a ASP.NET Web API controller that uses a service, which in
Suppose you create a class names Person using the builder pattern, and suppose the
Suppose I have a FruitDetector class which takes in a string and returns the
Suppose i have an XML file, that i use as local database, like this):
Suppose I have: Toby Tiny Tory Tily Is there an algorithm that can easily
Suppose I have a class with a constructor (or other function) that takes a
Suppose that I have the following python base class: class BaseClass(object): def a(): This
Suppose that I have a registration screen, and when the user clicks the Register
Suppose I have the following HTML: <div id=Wrapper> <div class=MyClass></div> <div class=MyClass></div> <div class=MyClass></div>
Suppose a scenario like below : Class User {} // User has Admin Role

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.