Add code examples, and documentation

This commit is contained in:
Aaron Po
2026-08-12 00:03:32 -04:00
commit 77c16e69f6
79 changed files with 4458 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
namespace Bridge_Example;
//This is one of the refined abstraction classes. Note that it can make use of _sender since it inherits it from its superclass. Note also that since EmailSender and SmsSender implement IMessageSender, their specific SendMessage() method will be called, depending on what's passed into the constructor (see the main method)
public class AlertNotification : Notification
{
public AlertNotification(IMessageSender sender)
: base(sender) { }
public override void Notify(string message)
{
_sender.SendMessage($"ALERT: {message}");
}
}

View File

@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<RootNamespace>Bridge_Example</RootNamespace>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,16 @@
#region
using System;
#endregion
namespace Bridge_Example;
//This is one of the concrete implementors, which implements the implementor interface IMessageSender
public class EmailSender : IMessageSender
{
public void SendMessage(string message)
{
Console.WriteLine($"Email sent: {message}");
}
}

View File

@@ -0,0 +1,7 @@
namespace Bridge_Example;
//This class is the implementor. It gets implemented by concrete classes.
public interface IMessageSender
{
void SendMessage(string message);
}

View File

@@ -0,0 +1,14 @@
namespace Bridge_Example;
//This is the abstraction
public abstract class Notification
{
protected readonly IMessageSender _sender;
protected Notification(IMessageSender sender)
{
_sender = sender;
}
public abstract void Notify(string message);
}

View File

@@ -0,0 +1,17 @@
namespace Bridge_Example;
internal class Program
{
private static void Main(string[] args)
{
Notification n1 = new AlertNotification(new EmailSender());
Notification n2 = new AlertNotification(new SmsSender());
Notification n3 = new ReminderNotification(new EmailSender());
Notification n4 = new ReminderNotification(new SmsSender());
n1.Notify("Server is down");
n2.Notify("Server is down");
n3.Notify("Meeting at 3pm");
n4.Notify("Meeting at 3pm");
}
}

View File

@@ -0,0 +1,13 @@
namespace Bridge_Example;
//This is one of the refined abstraction classes. Note that it can make use of _sender since it inherits it from its superclass. Note also that since EmailSender and SmsSender implement IMessageSender, their specific SendMessage() method will be called, depending on what's passed into the constructor (see the main method)
public class ReminderNotification : Notification
{
public ReminderNotification(IMessageSender sender)
: base(sender) { }
public override void Notify(string message)
{
_sender.SendMessage($"Reminder: {message}");
}
}

View File

@@ -0,0 +1,16 @@
#region
using System;
#endregion
namespace Bridge_Example;
//This is another concrete implementor class, which implements the implementor interface IMessageSender
public class SmsSender : IMessageSender
{
public void SendMessage(string message)
{
Console.WriteLine($"SMS sent: {message}");
}
}