コード例 #1
0
        static void Main(string[] args)
        {
            var artistResource = new ArtistResource(new Artist());
            var bookResource   = new BookResource(new Book());

            //Two different view for artist resource
            var longFormViewForArtist  = new LongFormView(artistResource);
            var shortFormViewForArtist = new ShortFormView(artistResource);

            //Two different view for book resource
            var longFormViewForBook  = new LongFormView(bookResource);
            var shortFormViewForBook = new ShortFormView(bookResource);

            //We can completely change the behavior of sources via theirs objects

            Console.WriteLine(longFormViewForArtist.generateHTML());
            Console.WriteLine(shortFormViewForArtist.generateHTML());
            Console.WriteLine(longFormViewForBook.generateHTML());
            Console.WriteLine(shortFormViewForBook.generateHTML());
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Book        book        = new Book("Feel Good", "C:/Books", "This is a Good Book", "Http://www.feelgood.com");
            MusicArtist musicArtist = new MusicArtist("Dua Lipa", "C:/MusicArtist", "Great Singer", "Http://www.dualipa.com");

            IResource bookResource        = new BookResource(book);
            IResource musicArtistResource = new MusicArtistResource(musicArtist);

            View bookLongFormView        = new LongFormView(bookResource);
            View musicArtistlongFormView = new LongFormView(musicArtistResource);

            View bookArtistShortFormView  = new ShortFormView(bookResource);
            View musicArtistShortFormView = new ShortFormView(musicArtistResource);

            Console.WriteLine(bookLongFormView.Show());
            Console.WriteLine(bookArtistShortFormView.Show());

            Console.WriteLine(musicArtistlongFormView.Show());
            Console.WriteLine(musicArtistShortFormView.Show());

            Console.ReadKey();
        }