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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:33:14+00:00 2026-05-19T11:33:14+00:00

class Address { private enum Component { NUMBER, STREET, STATE, COUNTRY } private Map<Component,

  • 0
class Address
{
  private enum Component
  {
    NUMBER,
    STREET,
    STATE,
    COUNTRY
  }

  private Map<Component, String> componentToValue = ...;
}

I’d like my class to contain two methods:

  1. One to indicate the value of each address component (so I can debug if anything goes wrong).
  2. One to return the address in a form expected by humans: “1600 Amphitheatre Parkway Mountain View, CA 94043”.

What is the best-practice for Object.toString()? Is it primary meant for #1 or #2? Is there a best-practice for the naming of these methods?

  • 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-19T11:33:14+00:00Added an answer on May 19, 2026 at 11:33 am

    Would you format an address the same way in a SMS message and in an HTML page? Would you format it the same way in English, French and Japanese?

    If no, then you have your answer : the presentation does not belong to the object, but to the presentation layer displaying the object. Unless the object is specifically made up for the presentation layer, for example if it is a HtmlI18nedAddress, use toString for debugging.

    Consider Date vs SimpleDateFormat. Date contains the state and SimpleDateFormat returns multiple representations.

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

Sidebar

Related Questions

public class Address{ private TypeAddress typeAddress; private String street; //Getters and Setters ... }
@Embeddable @MappedSuperclass public class Address { private String street; private String city; public String
My Address Class: public class Address implements java.io.Serializable { private String addressId; private String
I have the following two classes: public class Address { public string AddressLine1 {
I have this : [Flags] public enum InfoAbonne{civilite,name,firstname,email,adress,country } public class Formulaire { private
[spring 3.0.5] MVC I have on class like that: public class Address { private
So I got the Address class: class Address { private String streetAddress; private int
I have a class at server-side like this: public class Address { public Address(string
Say I have a simple address class like below: public class Address { public
I have two classes Address and Employee as follows: public class Address { public

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.