Advertisement
Guest User

Untitled

a guest
Jun 18th, 2015
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. enum IO_ERR
  2. is
  3. TIMEOUT,
  4. BAD_STATE
  5. end enum
  6.  
  7. interface istream
  8. is
  9. proc read(in byte[] buffer, size count) returns size, excepts IO_ERR; /*Procedures are non-pure; they can modify state, and can access global variables*/
  10. func end_of_input() returns bool; /*functions are pure; they cannot modify state, and can only modify parameters that are passed to them (a reference to the class is passed as an input parameter)*/
  11.  
  12. end interface
  13.  
  14.  
  15. interface ostream
  16. is
  17. proc write(out byte[] buffer, size count) returns size, excepts IO_ERR;
  18. func end_of_output() returns bool;
  19. end interface
  20.  
  21. interface seekable
  22. is
  23. func get_position() returns position;
  24. proc seek(position x) excepts SEEK_ERR;
  25. end interface
  26.  
  27. /*inerfaces can be compound*/
  28.  
  29. type iostream is istream ostream;
  30. type ipond is istream seekable;
  31. type opond is ostream seekable;
  32. type iopond is ipond opond;
  33.  
  34. /*The following two classes are identical*/
  35.  
  36. class File1
  37. implements iopond /*compound interfaces are decomposed and duplicates are removed*/
  38. is
  39. /*...*/
  40. end class
  41.  
  42. class File2
  43. implements istream ostream seekable
  44. is
  45. /*...*/
  46. end class
  47.  
  48.  
  49. /*interfaces can also inherit other interfaces*/
  50.  
  51. interface ipondx
  52. implements istream seekable
  53. is
  54. /*...*/
  55. end interface
  56.  
  57. interface opondx
  58. implements istream seekable
  59. is
  60. /*...*/
  61. end interface
  62.  
  63. interface iopondx
  64. implements ipondx opondx
  65. is
  66. /*...*/
  67. end interface
  68.  
  69. /*In the case of iopondx, the seek and get_position methods are assumed to have separate implementations for both ipondx and opondx. In the interface iopond, there can only be one implementation of the methods in the pond interface since it is only included once.*/
  70.  
  71. /*you can also have functions with unaliased compound types as parameters*/
  72.  
  73. func foo(in istream ostream pond a);
  74.  
  75. /*You can then pass objects of type File1 or File2 to foo, however:*/
  76.  
  77. class File3
  78. implements iopondx
  79. is
  80. /*...*/
  81. end class
  82.  
  83. /*It is not possible to pass objects of type File3 to foo, even though it implements the three interfaces. You must pass objects of a type that implements all three of those interfaces directly and not inherited from other interfaces (except with a cast, and only if single base class or implemented interface directly implements those interfaces)*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement