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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:32:26+00:00 2026-05-18T05:32:26+00:00

I have a class (MiddleMan) talks to a system and this talk is initialized

  • 0

I have a class (MiddleMan) talks to a system and this talk is initialized by the MiddleMan’s clients.

If a ‘talk’ is successfully completed, MiddleMan will generate a token and return it to its client.

The class design I have at the moment is like below:


class MiddleMan{
    private String token = null;
    private String param1;
    private String param2;
    private String amount;

    boolean isTalkSuccessful = false;

    public MiddleMan(String param1, String param2){
    this.amount = amount;
    this.param1 = param1;
    this.param2 = param2;
    }

    public String talk() throws ValidationException{

      //a private method validates param1 and param2
    validateParameters();

     //talk to backend system;
    isTalkSuccessful = talkToSystem();


    }

    Private void validateParameters() throws ValidationException {

    }

    private boolen talkToSystem(){

    }


    public boolean isTalkSuccessful(){
      return isTalkSuccessful;
    }

    public String getToken() throws Exception{
       if(isTalkSuccessful()){
          return token;
      }else{
        throw new Exception("cannot return token because talk is not  successful");
      }

     }



}

Does this look right to you? How would you refactor it?

  • 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-18T05:32:26+00:00Added an answer on May 18, 2026 at 5:32 am
    1. From where the amount come into play. It’s not in the list of instance variables, neither it’s there in the constructor argument. You need to fix this in your snippet to avoid confusion.
    2. The validation of parameters should be done in the constructor. In case the parameters are not valid throw some appropriate exception from the constructor. talk() method should not validate, as its name is suggesting.
    3. I can see you are calling isTalkSuccessful() method in your getToken(). I am assuming you want client to check this before calling getToken() to avoid exception. Isn’t it? And you have your check in place just in case client doesn’t call isTalkSuccessful(). Correct? So, if avoiding the exception is the whole point, why not just don’t throw any exception. Lets get rid of that public method isTalkSuccessful() and let the client call getToken(). In your getToken() method check the private field isTalkSuccessful and if it’s false return null. Why not?
    4. Do you really need setToken()? Who will invoke it?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class like this below shown. which contains the shopping items where the
I have class that looks like this: class A { public: class variables_map vm
I have class in server side and I want use method of this class
I have class B that has class A, this is simplified version of class
I have class GUI so I can create object like this: GUI g1 =
I have a class called LayoutManager. The purpose of this class is to hold
I have class to create user and return the info of user (success). class
I have class which has a method that needs to return three DataTables. I
I have class structure like this: class A1,A2,..,An extends A; class B1,B2,..,Bn extends B;
I have class (MyCustomWebView) that extend webview can i do something like this ?

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.