Last active
April 15, 2021 10:09
-
-
Save matt-goldman/bb904f5894456531fae7201a2e2bf03f to your computer and use it in GitHub Desktop.
Interfaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EmailNotifier : INotifier | |
{ | |
public void Send(string subject, string body, Owner recipient) | |
{ | |
// logic that sends email | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FeedingTime | |
{ | |
public void FeedPet(IEats pet) | |
{ | |
var food = new Food(); | |
pet.eat(food); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FeedingTime | |
{ | |
private EmailService _myEmailService; | |
public FeedingTime() | |
{ | |
_myEmailSerice = new EmailService(); // we probably have to pass in some SMTP details or something... | |
} | |
public void FeedPet(IEats pet) | |
{ | |
var food = new Food(); | |
pet.eat(food); | |
// assuming we have set up pet and owner properties for out pet... | |
_myEmailService.Send("Your pet has been fed", $"Your pet {pet.name} has been fed. Kind Regards, FeedingTime", pet.Owner.EmailAddress); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FeedingTime | |
{ | |
private INotifier _notifier; | |
public FeedingTime(INotifier notifier) | |
{ | |
_notifier = notifier; | |
} | |
public void FeedPet(IEats pet) | |
{ | |
var food = new Food(); | |
pet.eat(food); | |
// assuming we have set up pet and owner properties for out pet... | |
_notifier.Send("Your pet has been fed", $"Your pet {pet.name} has been fed. Kind Regards, FeedingTime", pet.Owner); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ISwims | |
{ | |
void swim(); | |
} | |
public class Fish : ISwims, IEats, ISleeps | |
{ | |
public void sleep() | |
{ | |
// logic for when your fish is sleeping... | |
} | |
public void eat(Food food) | |
{ | |
// logic for when your fish eats... | |
} | |
public void swim() | |
{ | |
// logic for when your fish is swimming... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EmailNotifier : INotifier | |
{ | |
private IGoldieEmail _goldieMail; | |
public EmailNotifier(IGoldieEmail goldieMail) | |
{ | |
_goldieMail = goldieMail; | |
} | |
public void Send(string subject, string body, Owner recipient) | |
{ | |
_goldieMail.SendEmail(body, subjcet, new string[] { recipient.EmailAddress }); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Startup | |
{ | |
// ommitted for clarity... | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddGoldieMail("senderAddress"); | |
} | |
// ommitted for clarity... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IEats | |
{ | |
void eat(Food food); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IGoldieEmail | |
{ | |
void SendEmail(string body, string subject, string[] recipients); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface INotifier | |
{ | |
void Send(string subject, string body, Owner recipient); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ISleeps | |
{ | |
void sleep(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Cat: IEats, ISleeps | |
{ | |
public void sleep() | |
{ | |
// logic for when your cat is sleeping... | |
} | |
public void eat(Food food) | |
{ | |
// logic for when your cat eats... | |
} | |
} | |
public class Dog: IEats, ISleeps | |
{ | |
public void sleep() | |
{ | |
// logic for when your dog is sleeping... | |
} | |
public void eat(Food food) | |
{ | |
// logic for when your dog eats... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Startup | |
{ | |
// ommitted for clarity... | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddSingleton<INotifier, EmailNotifier>(); | |
} | |
// ommitted for clarity... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment