java-ja 第1回 チキチキ『( ゜ェ゜)・;'.、ゴフッ』 - Strategy
Upcoming SlideShare
Loading in...5
×
 

java-ja 第1回 チキチキ『( ゜ェ゜)・;'.、ゴフッ』 - Strategy

on

  • 1,613 views

 

Statistics

Views

Total Views
1,613
Views on SlideShare
1,602
Embed Views
11

Actions

Likes
1
Downloads
3
Comments
0

3 Embeds 11

http://coderwall.com 6
http://s.deeeki.com 4
http://www.google.co.jp 1

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

java-ja 第1回 チキチキ『( ゜ェ゜)・;'.、ゴフッ』 - Strategy java-ja 第1回 チキチキ『( ゜ェ゜)・;'.、ゴフッ』 - Strategy Presentation Transcript

  • ( ) ;. Strategy @daisuke_m 2011/04/25
  • • @daisuke_m• @j5ik2o•• Java• Jiemamy• Apache Mahout
  • Strategy•••• ( ) → View slide
  • • … View slide
  • http://ja.wikipedia.org/wiki/Strategy_
  • " "• java.io.File
  • File•… • … • • …• file1, file2, file10 …
  • Strategy• case1 : •• case2 : if elseif elseif… •
  • /* case1 */void sort(List<File> target) { // sort by name}/* case2 */void sort(List<File> target, String type) { if ("name".equasls(type)) { // sort by name } else if ("size".equals(type)) { // sort by size } else { // default ... }}
  • Strategy• case 3 : ( ) •• case 4 : •
  • •" "
  • Strategy• •• • • → • SQL → RDBMS•
  • public interface Strategy { String process(int i);}public class Client { Strategy strategy; public Client(Strategy strategy) { this.strategy = strategy; } public void run() { for (int i = 1; i <= 100; i++) { System.out.println(strategy.process(i); } }}
  • /* FizzBuzz */public class FizzBuzzStrategy implements Strategy { public String process(int i) { if (i % 3 == 0 && i % 5 == 0) return "FizzBuzz"; if (i % 3 == 0) return "Fizz"; if (i % 5 == 0) return "Buzz"; return String.valueOf(i); }}/* Nabeatsu */public class NabeatsuStrategy implements Strategy { public String process(int i) { if (i % 3 == 0 || String.valueOf(i).contains("3")) { return i + " ( ´Д` ) ";; } return String.valueOf(i); }}
  • Client c = new Client( ); c.run();new FizzBuzzStrategy() new NabeatsuStrategy() FizzBuzz Nabeatsu 1 1 2 2 Fizz 3 ( ´Д` ) 4 4 Buzz 5 Fizz 6 ( ´Д` ) 7 7 8 8 9 ( ´Д` ) Fizz Buzz 10 11 11 12 ( ´Д` ) Fizz 13 13 ( ´Д` )