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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:59:42+00:00 2026-06-07T16:59:42+00:00

I have an (Java) object backed by a database table. In the database, a

  • 0

I have an (Java) object backed by a database table. In the database, a value of “N” in a (new)column implies something is forbidden, while a value of “Y” or null (default) implies that something is allowed.

In my object, I’m looking to have the same effect: by default forbidden = false, but it can be set to true, if desired. I’m working with existing code, so I don’t want to modify the constructor.

However, the way the property will be used is likely to be (and I think is more understandable) is positive: isAllowed()/setAllowed(). I have therefore set up my code as:

public boolean isAllowed()
{   return !this.forbidden;  }
public void setAllowed(boolean allowed)
{   this.forbidden = ! allowed;  }
  1. Does anyone else consider if ([!]isAllowed()) {...} to be more understandable than
    if ([!]isForbidden()) {...}, or am I making an erroneous assumption?
  2. Does my code make sense? (Yes, I’m trying to comment it properly, that’s why I’m asking.)
  3. My main question: Is there a conventional name for this kind of tweak? A boolean property backed by a field that carries the opposite value of the exposed property.

Thank you.

  • 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-07T16:59:44+00:00Added an answer on June 7, 2026 at 4:59 pm

    (1) Does anyone else consider if ([!]isAllowed()) {...} to be more understandable than if ([!]isForbidden()) {...}…

    Yes. Positives are usually the way to go. Not always, but usually. Consider the case where code wants to branch on whether something is allowed:

    if (something.isAllowed()) {
        // do the thing
    }
    

    vs.

    if (!something.isForbidden()) {
       // do the thing
    }
    

    The first just reads a lot more fluidly. (But this is subjective.)

    Just FWIW, I’d probably hold the data member as allowed rather than forbidden, too. So you wouldn’t be inverting it in the accessor. Because the argument above applies just as much to code that uses the field directly (assuming you have code that does) as to code using the accessor.

    (2) Does my code make sense?

    Other than the bracing style, yes. 🙂 (And style is just style, and completely your own decision.)

    (3) – My main question: Is there a conventional name for this kind of tweak?

    I’ve never heard one, it’s not really common enough. I suppose you’re doing something vaguely facade or adapter-like, but it’s a real stretch. 🙂

    • 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 java code: Object myObj = new ArrayList(); List myList
I have a DSL Java object, i.e. a POJO which returns this in setters
I have a Java Properties object that I load from an in-memory String ,
I have a java.sql.ResultSet object containg data from a query that was run. How
I have the following issue: A java object contains two arrays of core datastore
Let's say I have a java.util.Properties object. The Properties object has a method called
I have a Java function called testForNull public static void testForNull(Object obj) { if
Suppose I have a Java method that returns a HashMap object. Because a LinkedHashMap
I have been trying to add to the Watch window a Java Date object
In Java I have an object that looks like this : class MyDoc {

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.