Skip to content
Permalink
Browse files

Live coding log `TemplateMethod`

  • Loading branch information...
otiai10 committed Aug 6, 2014
1 parent fd2622a commit 374d8a0664db8e84417382cdf5def47ad13e0597
Showing with 45 additions and 2 deletions.
  1. +5 −0 TemplateMethod/src/CharDisplay.java
  2. +37 −2 TemplateMethod/src/Main.java
  3. +3 −0 TemplateMethod/src/StringDisplay.java
@@ -2,9 +2,14 @@
private char ch;
private String head = "<<";
private String tail = ">>";

public CharDisplay(char ch) {
this.ch = ch;
}
public CharDisplay(String s) {
// だめ this.ch = s.getBytes()[0];
this.ch = s.charAt(0);
}
public void open() {
System.out.print(this.head);
}
@@ -1,11 +1,46 @@
public class Main {
public static void main(String[] args) {
AbstractDisplay d1 = new CharDisplay('A');
AbstractDisplay d0 = new CharDisplay('B');
AbstractDisplay d1 = new CharDisplay("A");
AbstractDisplay d2 = new StringDisplay("Hello, World!!");
AbstractDisplay d3 = new StringDisplay("Hoge Fuga Piyo");

d0.display();
d1.display();
d2.display();
d3.display();
}
}
}
/*
open - process - close
*/
/*
イベントサイトのレスポンスが違う
class Crawler {
abstract url: sring;
crawl() {
c := this.getContent();
r := this.parse(c);
s := this.close();
}
getContet() {
return http.Get(this.url);
}
}
class AsahiBeerCrawler extends Crawler {
constructor() {
this.url = "http://asahi.com/campaign";
}
parse(c http.Response) {
// アサヒビールのページのHTMLをパースする具体的な処理
}
close() {
// アサヒビールのページのリクエストをクロースずる処理
}
}
class KirinBeerCrawler extends Crawler {
constructor() {
this.url = "http://kirin.com/?view=campaign";
}
}
*/
@@ -4,10 +4,12 @@
private String separator = "|";
private String lineSeparator = "+";
private String lineContent = "-";

public StringDisplay(String string) {
this.string = string;
this.width = string.getBytes().length;
}

public void open() {
this.printLine();
}
@@ -17,6 +19,7 @@ public void print() {
public void close() {
this.printLine();
}

private void printLine() {
System.out.print(this.lineSeparator);
for (int i = 0; i < this.width; i++) {

0 comments on commit 374d8a0

Please sign in to comment.
You can’t perform that action at this time.