code_junkie

Define an interface method that takes different parameters

Nov 11th, 2011
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. interface IMeasurementInterface
  2. {
  3. void Initialize();
  4. void Close();
  5. }
  6.  
  7. interface IMeasurementInterface
  8. {
  9. void Initialize();
  10. void Close();
  11. void Setup(object Parameters);
  12. }
  13.  
  14. public interface IMeasurement<PARAMTYPE> where PARAMTYPE : Parameters
  15. {
  16. void Init();
  17. void Close();
  18. void Setup(PARAMTYPE p);
  19. }
  20.  
  21. public abstract class Parameters
  22. {
  23.  
  24. }
  25.  
  26. public class DeviceOne : IMeasurement<ParametersForDeviceOne>
  27. {
  28. public void Init() { }
  29. public void Close() { }
  30. public void Setup(ParametersForDeviceOne p) { }
  31. }
  32.  
  33. public class ParametersForDeviceOne : Parameters
  34. {
  35.  
  36. }
  37.  
  38. class DeviceInterface
  39. {
  40. void Initialize(IController & Controller);
  41. void Close();
  42. bool ChangeParameter(const string & Name, const string & Value);
  43. bool GetParam(string & Name, string &Value );
  44. }
  45.  
  46. interface IController
  47. {
  48. Initialize(DeviceSpecific & Params);
  49. Close();
  50. bool ChangeParameter(string & Name, string & Value);
  51. bool ChangeParams(string & Name[], string &Value []);
  52. }
  53.  
  54. IController objController = new MeasurementDevice(MeasureParram);
  55.  
  56. DeviceInterface MeasureDevice = new DeviceInterface(objController);
  57.  
  58. string Value;
  59.  
  60. MeasureDevice.GetParam("Temperature", Value);
  61.  
  62. if (ConvertStringToInt(Value) > 80)
  63. {
  64. MeasureDevice.ChangeParameter("Shutdown", "True");
  65. RaiseAlert();
  66. }
  67.  
  68. public interface IMeasurementInterface
  69. {
  70. void Initialize();
  71. void Close();
  72. void Setup( IConfigurer config );
  73. }
  74.  
  75. public interface IConfigurer
  76. {
  77. void ApplyTo( object obj );
  78. }
  79.  
  80. public abstract ConfigurerBase<T> : IConfigurer where T : IMeasurementInterface
  81. {
  82. protected abstract void ApplyTo( T item );
  83.  
  84. void IConfigurator.ApplyTo(object obj )
  85. {
  86. var item = obj as T;
  87. if( item == null )
  88. throw new InvalidOperationException("Configurer can't be applied to this type");
  89. ApplyTo(item);
  90. }
  91. }
  92.  
  93. interface IMeasurementInterface
  94. {
  95. void Initialize();
  96. void Close();
  97. void Setup();
  98. void Read (FileReader as <whatever read file object you are using>)
  99. void Store (FileReader as <whatever read file object you are using>)
  100. string Name();
  101. }
Add Comment
Please, Sign In to add comment