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

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,674
On Slideshare
1,663
From Embeds
11
Number of Embeds
3

Actions

Shares
Downloads
4
Comments
0
Likes
1

Embeds 11

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

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. ( ) ;. Strategy @daisuke_m 2011/04/25
  • 2. • @daisuke_m• @j5ik2o•• Java• Jiemamy• Apache Mahout
  • 3. Strategy•••• ( ) →
  • 4. • …
  • 5. http://ja.wikipedia.org/wiki/Strategy_
  • 6. " "• java.io.File
  • 7. File•… • … • • …• file1, file2, file10 …
  • 8. Strategy• case1 : •• case2 : if elseif elseif… •
  • 9. /* 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 ... }}
  • 10. Strategy• case 3 : ( ) •• case 4 : •
  • 11. •" "
  • 12. Strategy• •• • • → • SQL → RDBMS•
  • 13. 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); } }}
  • 14. /* 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); }}
  • 15. 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 ( ´Д` )