観測ステーションモード


依存逆転の原則
抽象に依存し、修正や破壊ではなく可能な限り拡張します.
 public abstract class Subject
    {
        IList<IAccountObserver> observerList = new List<IAccountObserver>();

        public void AddObserver( IAccountObserver observer )
        {
            observerList.Add( observer );
        }
        public void RemoveObserver( IAccountObserver observer )
        {
            observerList.Remove( observer );
        }

        public void Notify( UserAccountArgs args )
        {
            foreach( IAccountObserver observer in observerList )
            {
                observer.Update( args );
            }
        }
    }    
 public class UserAccountArgs
    {
        public string PhoneNumber;
        public string Email;
    }
  public class BankAccount : Subject
    {
        public void WithDraw( UserAccountArgs args )
        {
            Notify( args );
        }
    }
  public interface IAccountObserver
    {
        void Update(UserAccountArgs args);
    }
 public class Mobile:IAccountObserver
    {
        public void Update( UserAccountArgs args )
        {
        }
    }
public class Emailer:IAccountObserver
    {
        public void Update( UserAccountArgs args )
        {
        }
    }

よびだし
 static void Main( string[] args )
        {
            Subject subject = new BankAccount();
            
            UserAccountArgs arg = new UserAccountArgs();
            arg.Email = "";
            arg.PhoneNumber = "";

            IAccountObserver observer1 = new Emailer();
            IAccountObserver observer2 = new Mobile();

            subject.AddObserver( observer1 );
            subject.AddObserver( observer2 );

            subject.Notify( arg );
        }

原則のためにモードはモードのためにコードではありません