Skip to content

Instantly share code, notes, and snippets.

@JoshReedSchramm
Forked from kberridge/task.cs
Created December 17, 2012 17:28
Show Gist options
  • Save JoshReedSchramm/4320106 to your computer and use it in GitHub Desktop.
Save JoshReedSchramm/4320106 to your computer and use it in GitHub Desktop.
/* So I didn't really address the naming piece, but I'd start by going down this route */
public class Task : ActiveRecord
{
public string Name { get; set; }
public int AssignedTo_UserId { get; set; }
public DateTime DueOn { get; set; }
private INotifier _notifier;
public Task(INotifier notifier) : this()
{
_notifier = notifier;
}
public Task()
{
// I feel like i'd just pass in the date in the constructor.
// If not required I'd make DueOn nullable
DueOn = DateTime.Now.AddDays(1);
}
override void AfterInsert()
{
if (_notifier != null)
_notifier.Notify(AssignedTo_UserId);
}
}
public class EmailNotifier : INotifier {
public void Notify(int who) {
Email.Send(who, "New Task", "You have been assigned a new task");
}
}
// Not sure I like the coupling of user id to notification
// but I'll save that for a later refactor
public interface INotifier {
void Notify(int who);
}
@kberridge
Copy link

How would you suppress the email notification in a case where you're creating a new task, but you don't want a notification?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment