Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var video = new Video() {Title = "Video1" };
            var videoEncoder = new VideoEncoder();      // Publisher
            var mailService = new MailService();        // Subscriber
            var messageService = new MessageService();  // Subscriber

            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;    // Adding the method pointer to the delegate.
            videoEncoder.VideoEncoded += messageService.OnVideoEncoded; // This is what populates the VideoEncodedEventHandler. This is a subscription.

            videoEncoder.VideoEncoding += mailService.OnVideoEncoding;
            videoEncoder.VideoEncoding += messageService.OnVideoEncoding;

            videoEncoder.Encode(video);                                 
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var video = new Video() { Title = "The Lonely Shepherd" };
            var videoEncoder = new VideoEncoder(); // Publisher
            var mailService = new MailService(); // Subscriber
            var messageService = new MessageService(); // Subscriber

            videoEncoder.VideoEnconded += mailService.OnVideoEnconded; // Add method *event reference
            videoEncoder.VideoEnconded += messageService.OnVideoEncoded; // Add another method *event reference

            /* This way, we have to make changes to VideoEncoder class?
               We do not net to change that class anymore, the only thing we have to do
               does not need recompilation and redeployment.
               We can add another class, nothing will be affected in the VideoEncoder class. */

            videoEncoder.Encode(video);
        }