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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:04:29+00:00 2026-06-10T11:04:29+00:00

I have read some about the use of getters/setters in object oriented programming and

  • 0

I have read some about the use of getters/setters in object oriented programming and many resources such as this suggest that they should be used very infrequently. A quote from that article says:

Don’t ask for the information you need to do the work; ask the object that has the information to do the work for you.

While that sounds good in principle, I’m not particularly sure how that is best implemented. Say taht I have a class the describes a car. Inside that class, lets say that the brand of this car stored in the class is “Toyota”. Now I have a GUI that wants to display that this is a “Toyota”. How does one do that without a getter?

Even if I abstract out that the “Toyota” is stored as a String and return a TextBox with “Toyota” already written in it, this sounds, at best, like a getter of a wrapped form of the original property. I just thought that things like TextBoxes should be only in the GUI’s class, and not in helper classes like my car class here.

  • 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-10T11:04:31+00:00Added an answer on June 10, 2026 at 11:04 am

    You’re ignoring “to do the work”. If the work you want done is the brand of the car, then a getter that returns the brand does the work.

    What the article is saying is if you want work done on class data, put the work in the class. Do not pull data out of the class, do work on it, then return it to the class:

    var c = new Car();
    c.Odometer += 10;  // bad
    c.DriveMiles(10);  // good
    

    I also question how applicable that article is to C#; it claims:

    Getter and setter methods (also known as accessors) are dangerous for the same reason that public fields are dangerous: They provide external access to implementation details.

    In C# this is false, a C# accessor can accept arbitrary classes, they do not “provide external access to implementation details”.

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

Sidebar

Related Questions

I have read some posts about this topic and the answers are comet, reverse
I have read some questions about this in the last week or so, on
I have read some articles about using spatial optimized tables. Actually I use stored
I have read some threads about this already but I don't understand the code,
I have just switched from svn to mercurial and have read some tutorials about
I have read through some tutorials about javascript prototypal inheritance patterns but I am
I have read some posts on here about not mixing parameters when passing into
I've read some docs about the .NET Garbage Collector but i still have some
I have read various articles about passing variables around using RMI. Some of them
I have some question about WH_MOUSE. From what I've read, by putting the hook

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.