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

  • Home
  • SEARCH
  • 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 6675433
In Process

The Archive Base Latest Questions

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

I have a class say Test.java and it includes a member variable called errorCode

  • 0

I have a class say Test.java and it includes a member variable called errorCode which belongs to the class ErrorCode which is nothing but a wrapper over a int errorCode … My question is about the setter and getters, what should be the ideal signature for them. The errorCode is an int so the setter would be something like

class Test{
ErrorCode errorCode;
    public void setCode(int errorCode)
    { 
        this.errorCode = new ErrorCode(errorCode);
    }

   public int getCode()
    { 
       return this.errorCode.getCode();
    }
}

So should, the class create the object and let the client pass in an int or should the client create the object and class only set it to its member variable, ideally should we favor the client or the 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-05-26T03:51:19+00:00Added an answer on May 26, 2026 at 3:51 am

    I’d say that, if at all possible, you should set things up so that your Test class doesn’t need to know what the internals of ErrorCode are. Right now it’s a wrapper around an int, but perhaps in the future it will need to be something else, or you may have multiple subclasses of ErrorCode.

    Better for Test to accept and return ErrorCode objects, and let ErrorCode itself handle creating instances. You may want to give ErrorCode some static factory methods such as

    static ErrorCode createFromInt(int code) {
       return new ErrorCode(code);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have the following code: import java.lang.InterruptedException; import javax.swing.SwingWorker; public class Test {
say I have: class Test { public static int Hello = 5; } This
Let's say I have the following class: public class Test<E> { public boolean sameClassAs(Object
Say I have a Metal class named Preview. How do I test it with
Lets say i have this usercontrol public class test : UserControl { public int
Here is simplified version of my requirement I have a java class say Processor
Say I have a class object named test. test has various methods, one of
I have a class test which isn't standard constructable nor assignable due to certain
I have a program Test.java: import java.io.*; public class Test { public static void
I have a simple servlet say com.test.HelloWorld.class then I create these folders tree: WEB-INF

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.