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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:06:11+00:00 2026-06-05T03:06:11+00:00

If I have a User object with the properties/fields ‘firstName’ and ‘lastName’. Would it

  • 0

If I have a User object with the properties/fields ‘firstName’ and ‘lastName’. Would it always be best to set and get each field with a firstName and lastName getter/setter, or would a simple ‘name’ getter/setter be acceptable?

  • 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-05T03:06:13+00:00Added an answer on June 5, 2026 at 3:06 am

    It largely depends on what language you’re planning to use these variables in. In languages where accessors (gets) and mutators (sets) are written out by hand and aren’t inherently present, there are a number of ways to handle these functions.

    Public variables are generally frowned upon, but provide direct access to use and change the values. People can argue for or against public and protected variables, but general consensus in OOP is that you should keep your data to yourself. Since you have already mentioned get/set, we’ll assume you’re not going to be doing this.

    Another way to address access to the variables is to return a reference, but as in the first example, your mileage may vary. There’s a lot of responsibility in providing direct access and a lot of that is left directly on the user’s shoulders. If you’re planning to have people other than yourself working with this class, it’s not especially safe to give them such access.

    Standard getName() and setName() functions are the simplest way to handle it and provide a format that can be easily updated without changing the interface. Once your program is a decent size, refactoring interface changes can become a nightmare. This route allows you do gut the functions without changing anything else in your code.

    In languages that support it, you can write overloaded functions that will decide based on syntax whether you want to retrieve the data or change the data. This follows the same basic idea as your standard get/set, however the calling syntax would be more akin to user.name("Joebob Peoplesmith") or name = user.name(). The way of going about this varies language to language, as does the ability.

    Finally, some languages have built-in access for variables that are declared in certain ways. A good example is Objective-C’s property, which can be synthesized with a private variable for direct access as a get/set interface. In this format, to access NSString *m_pFirstName, you can create @property NSString *firstName and then @synthesize firstName = m_pFirstName. The get/set is implicitly handled by user.firstName as if it were a local variable.

    As for combining your firstName and lastName, that is a personal choice and should be decided based on whether or not you would ever want/need to change anything individually. Ask yourself:

    • Do I ever need to just change firstName or lastName?
    • Do I ever need to just access firstName or lastName?
    • How do I plan to return firstName + lastName? (an array? a combined string?)
    • Who will be using these functions? (other developers? other classes?)
    • Will this be self-explanatory to newcomers? (easy to understand? easy to use? ‘fool-proof’?)
    • Is there a data structure that can help me?

    Overall, you need to research your options based on language restrictions and plan out how you will be using your variables before making your decisions. Avoid having to refactor mid-development if at all possible. Hope this helps!

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

Sidebar

Related Questions

I have a domain object called User . Properties of user include ssoId, name,
I have a user control which uses objects as inner properties (some code is
Following scenario: I have user object: ... @Column(name = TITLE) private String title; @NotNull
I want to integrate chargify to my rails app. I have user object and
I have an user object for my restful service, which has an userid and
Let's say I have an object - a User object in this case -
I have an issue with Knockout where I prototype a user object where the
I have a data model object User . My app also has some other
I have a script which creates a user-defined object like this: obj = new
Suppose I have a user defined type: CREATE OR REPLACE TYPE TEST_TYPE AS OBJECT

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.