コード例 #1
0
        static void DP_Program()
        {
            Console.WriteLine("--------------------------------------------\n" +
                              "              Observer Program              \n" +
                              "--------------------------------------------");
            Library2 tarver  = new Library2(null, DPInitBookList);
            Person2  anna    = new Person2("Anna Smith");
            Person2  brad    = new Person2("Brad Cooper");
            Person2  charles = new Person2("Charles Brown");

            tarver.AddUser(anna);
            tarver.AddUser(brad);
            tarver.AddUser(charles);

            //Anna checks out Great Expectations.
            tarver.HandleBookRequest(anna, "Great Expectations");
            //Now, Brad wants to check out the book, but Anna still has it.
            tarver.HandleBookRequest(brad, "Great Expectations");
            //Then, Anna finishes Great Expectations and returns it.
            tarver.CheckInBook(anna);
            //At this point, Brad should get his book.
            //While Brad is reading Great Expectations,
            //  he wants to reserve American Gods.
            tarver.HandleBookRequest(brad, "American Gods");
            //Meanwhile, Charlie checks out American Gods.
            tarver.HandleBookRequest(charles, "American Gods");
            //Anna requests American Gods.
            tarver.HandleBookRequest(anna, "American Gods");
            //Even though Brad is on the wait list for American Gods,
            //  Anna receives it when Charlie returns it.
            tarver.CheckInBook(charles);
            //Anna returns American Gods.
            tarver.CheckInBook(anna);
            //Now Brad returns Great Expectations.
            //Then, Brad gets American Gods right away.
            tarver.CheckInBook(brad);

            Console.ReadLine();
            return;
        }
コード例 #2
0
 public Subscription(Person2 person2, IObserver <Event> observer)
 {
     this.person2 = person2;
     Observer     = observer;
 }