/Users/lyon/j4p/src/futils/PolymorphicProcessor.java

1    package futils; 
2     
3    import java.io.BufferedReader; 
4     
5    public class PolymorphicProcessor { 
6        LineProcessor lp = null; 
7     
8        public PolymorphicProcessor(LineProcessor _lp) { 
9            lp = _lp; 
10           process(); 
11       } 
12    
13       public void process() { 
14           BufferedReader br = 
15                   ReaderUtil.getBufferedReader("select text file"); 
16           String s = null; 
17           while ((s = ReaderUtil.readLine(br)) != null) { 
18               lp.process(s); 
19           } 
20           ReaderUtil.close(br); 
21    
22       } 
23    
24       public static void main(String args[]) { 
25           new PolymorphicProcessor( 
26                   new MyLineProcessor() 
27           ); 
28       } 
29    
30       private static class MyLineProcessor implements LineProcessor { 
31           public void process(String s) { 
32               System.out.println(s); 
33           } 
34       } 
35   } 
36    
37    
38    
39    
40