Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Task
- {
- public Status Status { get; set; }
- public virtual void Close()
- {
- Status = Status.Closed;
- }
- }
- public ProjectTask : Task
- {
- public override void Close()
- {
- if (Status == Status.Started)
- throw new Exception("Cannot close a started Project Task");
- base.Close();
- }
- }
- public class Task {
- public Status Status { get; set; }
- public virtual bool CanClose() {
- return true;
- }
- public virtual void Close() {
- Status = Status.Closed;
- }
- }
- public ProjectTask : Task {
- public override bool CanClose() {
- return Status != Status.Started;
- }
- public override void Close() {
- if (Status == Status.Started)
- throw new Exception("Cannot close a started Project Task");
- base.Close();
- }
- }
- public class Task {
- public Status Status { get; private set; }
- public virtual bool CanClose(out String reason) {
- reason = null;
- return true;
- }
- public void Close() {
- String reason;
- if (!CanClose(out reason))
- throw new Exception(reason);
- Status = Status.Closed;
- }
- }
- public ProjectTask : Task {
- public override bool CanClose(out String reason) {
- if (Status != Status.Started)
- {
- reason = "Cannot close a started Project Task";
- return false;
- }
- return base.CanClose(out reason);
- }
- }
- // Moves the task to the closed state
- // and does not throw any Exception.
- public virtual void Close()
- {
- Status = Status.Closed;
- }
- // Behaviour: Moves the task to the closed status if possible.
- // If this is not possible, this method throws an Exception
- // and leaves the status unchanged.
- // Default behaviour: Moves the task to the closed state
- // and does not throw any Exception.
- public virtual void Close()
- {
- Status = Status.Closed;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement