
ImageProcessor portion:
1: namespace TemplateMethodConsole
2: { 3: abstract class ImageProcessor
4: { 5: public void ProcRoutine()
6: { 7: Input();
8: ImageProc();
9: Output();
10: }
11: public virtual void Input()
12: { 13: Console.Write("Load file: "); 14: }
15: public virtual void ImageProc()
16: { 17: Console.Write("Image processing: "); 18: }
19: public virtual void Output()
20: { 21: Console.Write("Output file: "); 22: }
23: }
24: }
Filter2D portion:
1: namespace TemplateMethodConsole
2: { 3: class Filter2D : ImageProcessor
4: { 5: public override void Input()
6: { 7: base.Input();
8: Console.WriteLine("Read a bmp-format image"); 9: }
10: public override void ImageProc()
11: { 12: base.ImageProc();
13: Console.WriteLine("Perform Filter2D."); 14: }
15: public override void Output()
16: { 17: base.Output();
18: Console.WriteLine("Write a bmp-format image"); 19: }
20: }
21: }
PrymidDown portion:
1: namespace TemplateMethodConsole
2: { 3: class PrymidDown : ImageProcessor
4: { 5: public override void Input()
6: { 7: base.Input();
8: Console.WriteLine("Read a jpeg-format image"); 9: }
10: public override void ImageProc()
11: { 12: base.ImageProc();
13: Console.WriteLine("Perform downsampling."); 14: }
15: public override void Output()
16: { 17: base.Output();
18: Console.WriteLine("Write a jpeg-format image"); 19: }
20: }
21: }
GaussianFilter portion:
1: namespace TemplateMethodConsole
2: { 3: class GaussianFilter:ImageProcessor
4: { 5: public override void Input()
6: { 7: base.Input();
8: Console.WriteLine("Read a xml-format image"); 9: }
10: public override void ImageProc()
11: { 12: base.ImageProc();
13: Console.WriteLine("Perform Gaussian filter."); 14: }
15: public override void Output()
16: { 17: base.Output();
18: Console.WriteLine("Write a xml-format image"); 19: }
20: }
21: }
Console portion:
1: class Program
2: { 3: static void Main(string[] args)
4: { 5: ImageProcessor ip1 = new PrymidDown();
6: ImageProcessor ip2 = new Filter2D();
7: ImageProcessor ip3 = new GaussianFilter();
8:
9: ip1.ProcRoutine();
10: Console.WriteLine("-----------------"); 11: ip2.ProcRoutine();
12: Console.WriteLine("-----------------"); 13: ip3.ProcRoutine();
14: Console.WriteLine("-----------------"); 15: Console.ReadKey();
16: }
17: }

me1237guy 發表在
痞客邦
留言(0)
人氣(
22
)
請先 登入 以發表留言。