コード例 #1
0
ファイル: Program.cs プロジェクト: hogwashpz/DesignPatterns
        static void Main(string[] args)
        {
            Console.WriteLine("Decorator Pattern !!!" + Environment.NewLine);

            BaseDataSource file = new FileDataSource(Environment.CurrentDirectory);
            // Decorate component
            BaseDataSourceDecorator encryptedFile = new EncryptionDecorator(file);
            BaseDataSourceDecorator compressFile  = new CompressionDecorator(encryptedFile);

            var resultFile = compressFile.ReadData();

            Console.WriteLine(resultFile);
            Console.WriteLine();

            // Other way
            BaseDataSource stream = new StreamDataSource("www.example.com");

            // Decorate component
            stream = new EncryptionDecorator(stream);
            stream = new CompressionDecorator(stream);

            var resultStream = stream.ReadData();

            Console.WriteLine(resultStream);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ivan-kohut/design-patterns
        static void Main(string[] args)
        {
            IDataSource fileDataSource      = new FileDataSource("test-file.txt");
            IDataSource encryptedDataSource = new EncryptionDecorator(fileDataSource);

            string data = encryptedDataSource.ReadData();

            Console.WriteLine();

            encryptedDataSource.WriteData(data);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            IDataSource dataSource = new FileDataSource("data.sql");

            IDataSource compressedDataSource = new ComporessionDecorator(dataSource);

            compressedDataSource.ReadData();
            compressedDataSource.WriteData(new object());

            // output:
            //      data.sql readed.
            //      Data compressed.
            //      Compressed data was written to data.sql.
        }