示例#1
0
        static void Main(string[] args)
        {
            var formatter = new StandardFormatter();
            var buildings = new List <IBuilding>();

            var apartment = new Apartment();

            apartment.Description = "Nice apartment.";
            apartment.Rooms.Add("1/A", "Cozy little room");
            apartment.Rooms.Add("2/C", "To be renovated");
            buildings.Add(apartment);

            var house = new House();

            house.Address     = "New Street";
            house.Description = "Large family home.";
            house.Owner       = "Mr. Smith.";
            buildings.Add(house);

            var trainStation = new TrainStation();

            trainStation.Director           = "Mr. Kovacs";
            trainStation.Location           = "Budapest";
            trainStation.NumberOfPassangers = 100000;
            trainStation.NumberOfTrains     = 100;
            buildings.Add(trainStation);

            foreach (var building in buildings)
            {
                building.Print(formatter);
            }

            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            List <Manuscript> manuscripts = new List <Manuscript>();

            // Instantiate the formatters
            IFormatter standardFormatter  = new StandardFormatter();
            IFormatter backwardsFormatter = new BackwardsFormatter();
            IFormatter fancyFormatter     = new FancyFormatter();

            FAQ faq = new FAQ(standardFormatter);

            faq.QuestionAnswers.Add("Question 1", "Hello World");
            faq.QuestionAnswers.Add("Question 2", "May the force be with you");
            faq.QuestionAnswers.Add("Question 3", "Rest in Peace!");
            manuscripts.Add(faq);

            Book book = new Book("New book of patterns", "Raghu", "John Doe", backwardsFormatter);

            manuscripts.Add(book);

            Manuscript paper = new Paper("Design Patterns", "Wiki", "Ravi", "Nothing", fancyFormatter);

            manuscripts.Add(paper);

            foreach (var item in manuscripts)
            {
                item.Print();
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            List<Manuscript> manuscripts = new List<Manuscript>();

            // Instantiate the formatters
            IFormatter standardFormatter = new StandardFormatter();
            IFormatter backwardsFormatter = new BackwardsFormatter();
            IFormatter fancyFormatter = new FancyFormatter();

            FAQ faq = new FAQ(standardFormatter);
            faq.QuestionAnswers.Add("Question 1", "Hello World");
            faq.QuestionAnswers.Add("Question 2", "May the force be with you");
            faq.QuestionAnswers.Add("Question 3", "Rest in Peace!");
            manuscripts.Add(faq);

            Book book = new Book("New book of patterns", "Raghu", "John Doe", backwardsFormatter);
            manuscripts.Add(book);

            Manuscript paper = new Paper("Design Patterns", "Wiki", "Ravi", "Nothing", fancyFormatter);
            manuscripts.Add(paper);

            foreach (var item in manuscripts)
            {
                item.Print();
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            var document          = new List <Manuscript>();
            var fancyFormatter    = new FancyFormatter();
            var standardFormatter = new StandardFormatter();

            var faq = new FAQ(standardFormatter)
            {
                Title = "The Bridge pattern"
            };

            faq.Questions.Add("What is it?", "A design pattern.");
            faq.Questions.Add("When do we use it?", "When you need to separate the abstraction from an implementation.");
            document.Add(faq);

            var book = new Book(fancyFormatter)
            {
                Author = "John Sonemz",
                Title  = "Lots of Patterns",
                Text   = "Blah blah blah"
            };

            document.Add(book);

            foreach (var doc in document)
            {
                doc.Print();
            }
        }
        static void Main(string[] args)
        {
            var documents         = new List <Manuscript>();
            var standardFormatter = new StandardFormatter();
            var reverseFormatter  = new ReverseFormatter();
            var fancyFormatter    = new FancyFormatter();

            var faq = new FAQ(standardFormatter);

            faq.Title = "The Bridge Pattern FAQ";
            faq.Questions.Add("What is it?", "A design pattern.");
            faq.Questions.Add("When do we use it?", "When you need to separate an abstraction from an implementation.");
            documents.Add(faq);

            var book = new Book(fancyFormatter)
            {
                Title  = "Lots of patterns",
                Author = "John Sonmez",
                Text   = "Blah Blah Blah..."
            };

            documents.Add(book);
            var paper = new TermPaper(reverseFormatter)
            {
                Class      = "Design Patterns",
                Student    = "Joe N00b",
                Text       = "Blah Blah Blah...",
                References = "GOF"
            };

            documents.Add(paper);

            documents.ForEach(m => m.Print());
            ReadKey();
        }
示例#6
0
        static void Main(string[] args)
        {
            var standardFormatter = new StandardFormatter();
            var reversedFormatter = new ReversedFormatter();

            var documents = new Document[]
            {
                new Report(standardFormatter)
                {
                    Title   = "Report A",
                    Author  = "Author A",
                    Summery = "A new report is generated and everything is normal."
                },
                new Essay(reversedFormatter)
                {
                    Title        = "Essay A",
                    Author       = "Author C",
                    Introduction = "Everything is working."
                },
                new Report(standardFormatter)
                {
                    Title   = "Report c",
                    Author  = "Author B",
                    Summery = "A new report is generated and everything is Ok."
                }
            };

            foreach (var document in documents)
            {
                Console.WriteLine("=======================================");
                document.Print();
                Console.WriteLine("=======================================");
            }
        }
示例#7
0
        static void Main(string[] args)
        {
            List <Manuscript> documents = new List <Manuscript>();

            var standFormatter = new StandardFormatter();
            var faq            = new FAQ(standFormatter);

            faq.Title = "The Bridge Pattern FAq";
            faq.Questions.Add("What is it?", "A design pattern");
            faq.Questions.Add("When do we use it?", "When you need to seperate an abstraction from an implementation");
            documents.Add(faq);


            var backwardsFormatter = new BackwardsFormatter();
            var book = new Book(backwardsFormatter)
            {
                Title  = "Design Patterns",
                Author = "Adrian Gurnett",
                Text   = "Blah blah blah"
            };

            documents.Add(book);


            var fancyFormatter = new FancyFormatter();
            var paper          = new TermPaper(fancyFormatter)
            {
                Class      = "Design Patterns",
                Student    = "Joe N00b",
                Text       = "Blah blah blah",
                References = "GOF"
            };

            documents.Add(paper);


            foreach (var document in documents)
            {
                document.Print();
            }


            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            var documents = new List <Manuscript>();

            // use different formatter
            var formatter = new StandardFormatter();
            //var formatter = new BackwardsFormatter();
            //var formatter = new FancyFormatter();

            var faq = new Faq(formatter);

            faq.Title = "The Bridge Pattern FAQ";
            faq.Questions.Add("What is it?", "A design pattern");
            faq.Questions.Add("When do we use it?", "When you need to separate an abstraction from an implementation.");
            documents.Add(faq);

            var book = new Book(formatter)
            {
                Title  = "Lots of Patterns",
                Author = "John Sonmez",
                Text   = "Blah blah blah..."
            };

            documents.Add(book);

            var paper = new TermPaper(formatter)
            {
                Class      = "Design Patterns",
                Student    = "Joe N00b",
                Text       = "Blah blah blah...",
                References = "GOF"
            };

            documents.Add(paper);

            foreach (var doc in documents)
            {
                doc.Print();
            }

            Console.ReadKey();
        }
示例#9
0
        static void Main()
        {
            List <Document>  documents = new List <Document>();
            IFormatterBridge formatter = new StandardFormatter();

            var book = new Book(formatter)
            {
                Author = "Dan Brown",
                Title  = "The Da Vinci Code",
                Text   = "Blah blah blah ..."
            };

            documents.Add(book);

            var paper = new TermPaper(formatter)
            {
                Class      = "Software Engineering",
                Student    = "Jeremy Hall, Clara Knight",
                References = "SWE101",
                Text       = "Blah blah blah ..."
            };

            documents.Add(paper);

            var faq = new FAQ(formatter)
            {
                Title = "Design Patterns"
            };

            faq.Questions.Add("Who owns this?", "No one");
            faq.Questions.Add("Who created this?", "No one");
            documents.Add(faq);

            foreach (var document in documents)
            {
                document.Print();
            }

            Console.ReadLine();
        }