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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:38:58+00:00 2026-06-06T01:38:58+00:00

In Java I use getters/setters when I have simple models/pojos. I find that the

  • 0

In Java I use getters/setters when I have simple models/pojos. I find that the code becomes self-documenting when you do it this way. Calling getName() will return a name, I don’t need to care how it’s mapped to some database and so on.

Problems rise when using languages where getters and setters start feeling clunky, like in Python, and I often hear people saying that they are bad. For example some time a go I had a PHP project in which some of the data was just queried from the database and column values mapped to the objects/dictionaries. What I found out was that code like this was annoyingly hard to read, you can’t really just read the code, you read the code, then you notice that the values are fetched from the database and now you have to look through the database schema all the time to understand it. When all you could do is just look at the class definition and knowing that there won’t be any undocumented magic keys there.

So my question is how do you guys document code without getters and setters?

  • 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-06T01:38:59+00:00Added an answer on June 6, 2026 at 1:38 am

    In my opinion, there shouldn’t be any undocumented attributes in a class. PHP and other languages allow you to just stick attributes on a class from anywhere, whether they’ve been defined in the class or not. I think that’s bad practice for the reasons you describe and more:

    It’s hard to read.

    It makes it harder for other programmers (including your future self) to understand what’s going on.

    It prevents auto-complete functionality in IDEs from working.

    It often makes the domain layer too dependent on the persistence layer.

    Whether you use getters and setters to access the defined attributes of a class is a little more fungible to me. I like things to be consistent, so if I have a class that has a getChildren() method to lazy load some array of objects, then I don’t make the $children attribute public, and I tend to make other attributes private as well. I think that’s a little more a matter of taste, but I find it annoying to access some attributes in a class directly ($object->name;) and others by getters/setters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When referring to internal private variables of Java POJOs that have getters/setters, I've used
Possible Duplicate: Why use getters and setters? I have read books on Java, saying
In Java we use System.setProperty() method to set some system properties. According to this
How can I use java reflection or similar to find project name by just
I am working on a short java assignment that I have been set. The
First I would like to say that I have only worked with java for
I understand that this question is similar to others asking about Java Properties, and
If I have an object with 50 getters/setters, where every 10 of them is
I have a few questions about getters and setters for arrays. Suppose we have
i have a java class like this public class A { private String field1;

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.