Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. public class Task
  2. {
  3. public Status Status { get; set; }
  4.  
  5. public virtual void Close()
  6. {
  7. Status = Status.Closed;
  8. }
  9. }
  10.  
  11. public ProjectTask : Task
  12. {
  13. public override void Close()
  14. {
  15. if (Status == Status.Started)
  16. throw new Exception("Cannot close a started Project Task");
  17.  
  18. base.Close();
  19. }
  20. }
  21.  
  22. public class Task {
  23. public Status Status { get; set; }
  24. public virtual bool CanClose() {
  25. return true;
  26. }
  27. public virtual void Close() {
  28. Status = Status.Closed;
  29. }
  30. }
  31.  
  32. public ProjectTask : Task {
  33. public override bool CanClose() {
  34. return Status != Status.Started;
  35. }
  36. public override void Close() {
  37. if (Status == Status.Started)
  38. throw new Exception("Cannot close a started Project Task");
  39. base.Close();
  40. }
  41. }
  42.  
  43. public class Task {
  44. public Status Status { get; private set; }
  45.  
  46. public virtual bool CanClose(out String reason) {
  47. reason = null;
  48. return true;
  49. }
  50. public void Close() {
  51. String reason;
  52. if (!CanClose(out reason))
  53. throw new Exception(reason);
  54.  
  55. Status = Status.Closed;
  56. }
  57. }
  58.  
  59. public ProjectTask : Task {
  60. public override bool CanClose(out String reason) {
  61. if (Status != Status.Started)
  62. {
  63. reason = "Cannot close a started Project Task";
  64. return false;
  65. }
  66. return base.CanClose(out reason);
  67. }
  68. }
  69.  
  70. // Moves the task to the closed state
  71. // and does not throw any Exception.
  72. public virtual void Close()
  73. {
  74. Status = Status.Closed;
  75. }
  76.  
  77. // Behaviour: Moves the task to the closed status if possible.
  78. // If this is not possible, this method throws an Exception
  79. // and leaves the status unchanged.
  80. // Default behaviour: Moves the task to the closed state
  81. // and does not throw any Exception.
  82. public virtual void Close()
  83. {
  84. Status = Status.Closed;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement