我希望我的课程包含两个方法:
I'd like my class to contain two methods:
Object.toString()的最佳做法是什么?它主要用于#1或#2吗?这些方法的命名是否有最佳实践?
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?
推荐答案您是否会以相同的方式在SMS消息和HTML页面中设置地址格式?您会用英语,法语和日语将其格式化吗?
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?
如果否,那么您的答案是:表示不属于对象,而是属于显示对象的表示层.除非对象专门用于表示层,例如,如果它是HtmlI18nedAddress,则使用toString进行调试.
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.
考虑Date与SimpleDateFormat. Date包含状态,SimpleDateFormat返回多个表示形式.
Consider Date vs SimpleDateFormat. Date contains the state and SimpleDateFormat returns multiple representations.
更多推荐
toString():用于调试还是用于人类?
发布评论