Skip to content

Instantly share code, notes, and snippets.

@kodaitakahashi
Created December 25, 2016 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kodaitakahashi/b6070ddf5ec29ef83c4d5d7caaf6919b to your computer and use it in GitHub Desktop.
Save kodaitakahashi/b6070ddf5ec29ef83c4d5d7caaf6919b to your computer and use it in GitHub Desktop.
Adapter HTMLジェネレーター(
package adapter;
public class HTML {
private String string;
public HTML(String string) {
this.string = string;
}
/**
* brタグの中にstringを表示する
*/
public void showWithBreak() {
System.out.println("<br>" + string + "</br>");
}
/**
* smallタグの中にstringを表示する
*/
public void showWithSmall() {
System.out.println("<small>" + string + "</small>");
}
/**
* stringタグの中にstringを表示する
*/
public void showWithStrong() {
System.out.println("<strong>" + string + "</string>");
}
}
package adapter;
public class Main {
public static void main(String[] args) {
Tag html = new PrintHTML("Hello World");
html.printBreak();
html.printSmall();
html.printStrong();
}
}
package adapter;
public class PrintHTML extends HTML implements Tag{
public PrintHTML(String string){
super(string);
}
public void printBreak() {
showWithBreak();
}
public void printSmall() {
showWithSmall();
}
public void printStrong() {
showWithStrong();
}
}
package adapter;
public interface Tag {
public abstract void printBreak();
public abstract void printSmall();
public abstract void prin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment