-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[W6.4h][F09-B4]Zhong ZhengXin #734
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Godxin Some comments added. Please close PR after reading.
|
||
for(Printable p: printables) { | ||
|
||
concatenatedStringResult.concat(p.getPrintableString() + " "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way you can do this is using the StringJoiner
class that java provides.
/** | ||
*Produces a printable string representation of the object | ||
*/ | ||
String getPrintableString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job having a header comment for this method. You may want to have a header comment for the interface, as well.
/** | ||
* Returns a concatenated version of the printable strings of each object. | ||
*/ | ||
String getPrintableString(Printable... printables){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, this method should be used somewhere.
Use interfaces [LO-Interfaces]:
Exercise: Add a Printable interface
1.Add a Printable interface
2.Add the following method (getPrintableString(Printable... printables) in a suitable place of some other class. Note how the method depends on the Interface.
"/**
*/
String getPrintableString(Printable... printables){"
3.The above method can be used to get a printable string representing a bunch of person details. For example, you should be able to call that method like this:
"//p is a Person object
return getPrintableString(p.getPhone(), p.getEmail(), p.getAddress()); "