接口
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace susuusu{ interface Interface1 { int calculate(int a, int b,int c); }}
加法类
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace susuusu{ class Add:Interface1 { public int calculate(int a, int b,int c) { return a + b + c; } }}
减法类
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace susuusu{ class Subtract:Interface1 { public int calculate(int a, int b, int c) { return a - b - c; } }}
乘法类
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace susuusu{ class Multiply:Interface1 { public int calculate(int a, int b, int c) { return a * b * c; } }}
除法类
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace susuusu{ class Except:Interface1 { public int calculate(int a, int b, int c) { return a / b / c; } }}
环境角色
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace susuusu{ class Environment { private Interface1 inter; public Environment(Interface1 face) { inter = face; } public Interface1 gewrt() { return inter; } public void setwrt(Interface1 face) { inter = face; } public int calculate(int a, int b,int c) { return inter.calculate(a, b,c); } }}
Main方法
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace susuusu{ class Program { static void Main(string[] args) { Add addss = new Add(); Environment environment = new Environment(addss); Console.WriteLine( environment.calculate(4, 5,7)); Subtract subtrss = new Subtract(); Environment environment1 = new Environment(subtrss); Console.WriteLine(environment1.calculate(911, 81, 2)); Multiply mulit = new Multiply(); Environment environment2 = new Environment(mulit); Console.WriteLine(environment2.calculate(12, 45, 12)); Except except1 = new Except(); Environment environment3 = new Environment(except1); Console.WriteLine(environment3.calculate(81, 9, 9)); Console.ReadLine(); } }}
总结
总的感觉来书还是控制台比较好写一些!在不同的环境下写相同的程序,感受一下不同!