Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. D *d = new Adapter();
  2. d->foo();
  3.  
  4. class C { /* ... */ public: int foo (); int bar (); };
  5.  
  6. class D /* ... */ { public: int foo (); };
  7.  
  8. public class C
  9. {
  10. public void foo()
  11. {
  12. }
  13.  
  14. public void bar()
  15. {
  16. }
  17. }
  18.  
  19. public class D
  20. {
  21. public void foo()
  22. {
  23. }
  24. }
  25.  
  26. public interface FooExecutor
  27. {
  28. void foo();
  29. }
  30.  
  31. public class CExecutor : FooExecutor
  32. {
  33. C cMember;
  34.  
  35. public CExecutor (C c)
  36. {
  37. cMember = c;
  38. }
  39.  
  40. public void foo()
  41. {
  42. cMember.foo();
  43. }
  44. }
  45.  
  46. public class DExecutor : FooExecutor
  47. {
  48. D dMember;
  49.  
  50. public DExecutor (D d)
  51. {
  52. dMember = d;
  53. }
  54.  
  55. public void foo()
  56. {
  57. dMember.foo();
  58. }
  59. }
  60.  
  61. List<FooExecutor> myList = new List<FooExecutor>();
  62. myList.Add(new CExecutor(new C());
  63. myList.Add(new DExecutor(new D());
  64.  
  65. foreach (FooExecutor f in myList)
  66. {
  67. f.foo();
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement