Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Godxin
Copy link

@Godxin Godxin commented Mar 1, 2018

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.

"/**

  • Returns a concatenated version of the printable strings of each object.
    */
    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()); "

Copy link

@k-l-a k-l-a left a 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() + " ");
Copy link

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();
Copy link

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){
Copy link

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.

@k-l-a k-l-a added the Reviewed label Mar 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants