Below, I define an IInstantNotification Interface. TextNotification Class and EmailNotification Class inherit from this interface.
public interface IInstantNotification<T> {
List<string> Addresses { get; set; }
string NotificationContent { get; set; }
T NotificationArguments { get; set; }
bool SendNotification();
}
public class TextNotification : IInstantNotification<TextArguments>
{
public List<string> Addresses { get; set; }
public string NotificationContent { get; set; }
public TextArguments NotificationArguments { get; set; }
public bool SendNotification(){
//send the message and confirm
return true;
}
public TextNotification(
List<string> p_Addresses,
string p_NotificationContent,
MailArguments p_NotificationArguments)
{
Addresses = p_Addresses;
NotificationContent = p_NotificationContent;
NotificationArguments = p_NotificationArguments;
}
}
public class EmailNotification : IInstantNotification<MailArguments>
{
...
}
I can then instantiate a class, pass the args, and send the message. Pretty straight forward.
TextNotification TextObj = new TextNotification(myAddresses,myNotifContent, myArgs);
bool success = TextObj.SendNotification();
Instead, I always end up doing something like the following: scrapping the interfaces and putting everything in a static class for organization purposes only.
public static class TextNotification
{
public static bool SendNotification(
List<string> p_Addresses,
string p_NotificationContent,
MailArguments p_NotificationArguments)
{
//send the message and confirm
return true;
}
}
public static class EmailNotification
{
...
}
It seems like the steps to take the action of sending a notification now have a lot less overhead (and are just as easy to understand).
bool success = TextNotification.SendNotification(myAddresses, myNotifContent, myArgs);
To my ignorant more functional programming oriented mindset, the latter is pretty simple and it seems like the best way to implement things. I have really been struggling wrapping my mind around the reason for doing it the more "OOP" way (like at the top of my post). I realize this might be too trivial of an example, but it is the best one I could come up with.
This is all coming from a middle-tier application code perspective. Oftentimes, my code intercepts an http request, invokes static functions to execute business-layer actions, and those actions call my data layer (which are just a bunch of static functions) that then call stored procedures and things bubble back up until the response is eventually returned to the client.
Representing business-layer actions with fancy OO design patterns seems pointless.
I humbly ask for someone to help me understand where my thinking is flawed. I really want to embrace the world of OOP and its fancy design patterns, as well as being able to fully leverage C# and its potential as an OOP language. I feel like I am doing a disservice to myself writing functional-first C# code...