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 604795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:04:37+00:00 2026-05-13T17:04:37+00:00

I’m trying to build a GraphBot class that can answer different questions about about

  • 0

I’m trying to build a GraphBot class that can answer different questions about about an associated graph such as path length, shortest path between two vertices, number of paths passing through a given vertex etc.

I’d like to be able to add new questions without changing any code inside the Bot, it is only responsible for receiving the question, delegating so some other algorithm to solve the question using the graph associated with the bot and returning the answer.

So something like this:

public class GraphBot {
    private Graph graph;

    public GraphBot(Graph graph) {
        this.graph = graph;
    }

    public Answer ask(Question question) {
        // delegate somehow to answer the question, providing the graph
        // return an Answer object encapsulating the answer
    }
}

public interface Answer {
    public toPrintableOutput();
}

public interface Question {
    // question methods go here... this is what I'm having trouble with
}

The trouble I’m having is that questions have associated conditions or parameters. For instance, the question “path length” between “A” and “B” has the question type (“path length”) which is something all questions will have, but also the parameters “A” and “B”. In comparison, the question “paths passing through vertex” will only have the parameter “C” representing the vertex.

I can’t think of a way of presenting a uniform interface so that the system can be easily extended to handle numerous different questions with different numbers and types of parameters. I could have a QuestionSolver that was associated with each Question in which case it wouldn’t matter if each Question had different attributes as the QuestionSolver could assert that the question is of a valid type but this would require a mapping of Question to QuestionSolver somewhere that would require updating whenever a new question is introduced.

What is the most extensible way of implementing this system so that new questions would not require tonnes of changes in loads of different classes? Really I want to be able to create an class implementing Question and maybe create a class that can solve that question and then have the GraphBot automatically able to handle that question.

  • 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-05-13T17:04:37+00:00Added an answer on May 13, 2026 at 5:04 pm

    What you can do is just have the ask() method be part of the Question interface, and take a Graph. That way, each Question has to know how to answer itself, and you don’t have to design a Question api that is future-extensible.

    EDIT: Why is this a better design than making the GraphBot be able to answer a Question?

    • Simplicity: As you’re finding out, it’s very hard to design a Question API that will take every possible data required into account for any question as well as figuring out how to compile that into a dynamic question asking algorithm. It’s much simpler to have custom code per Question that will know what to do with the publicly known Graph data.
    • Depndencies: Your initial approach makes the relatively stable GraphBot dependent on the definitely unstable Question. My approach reverses this dependency, making it all much simpler, which leads back into the last point.
    • Maintenance: I guarantee you wouldn’t be able to predict everything the Question class needs to make available. When (not if) you come across a change you need to make in the Question interface, every implementer will need to change. This will make your future you (or some other developer) hate your present you with the fiery passion of a thousand suns if there are more than a few Question implementers.

    In the end, I can’t think of a convincing reason to not make a question answer itself. Yes, it’s arguable that it doesn’t make a lot of sense from a purely abstract “does this align with the real world” point of view, but it’s both practical and not unreasonable for a question to handle it’s own answering. One thing to remember about OOP is that the similarities with the real world are for convenience, not as a rule. Don’t let yourself be straitjacketed by them.

    So now it would be like this:

    public class GraphBot {
        private Graph graph;
    
        public GraphBot(Graph graph) {
            this.graph = graph;
        }
    
        public Answer ask(Question question) {
            return question.ask(graph);
        }
    }
    
    public interface Answer {
        public toPrintableOutput();
    }
    
    public interface Question {
        public Answer ask(Graph graph);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.