コード例 #1
0
ファイル: Program.cs プロジェクト: kean0212/DesignPattern
        static void Main(string[] args)
        {
            // This needs an explicit type
            IDataSource dataSource = new FileDataSource("somefile.dat");

            dataSource.WriteData("Hello, world!");

            dataSource = new EncryptionDecorator(dataSource);
            dataSource.WriteData("Something confidential.");

            dataSource = new CompressionDecorator(dataSource);
            dataSource.WriteData("Something need to be compressed.");
        }
コード例 #2
0
        public void DumbUsageExample()
        {
            IDataSource source = new FileDataSource("somefile.data");

            source.WriteData();
            // The target file has been written with plain data.

            source = new CompressionDecorator(source);
            source.WriteData();
            // The target file has been written with compressed data.

            source = new EncryptionDecorator(source);
            source.WriteData();
            // The target file has been written with encrypted data.
        }
コード例 #3
0
        static void Main(string[] args)
        {
            List <object> commandParameters = new List <object>();

            commandParameters.Add(1);
            commandParameters.Add(2);
            Command command = new Command(commandParameters);
            Flux    flux    = new Flux();
            CompressionDecorator compressedFlux          = new CompressionDecorator(flux);
            EncryptionDecorator  encryptedCompressedFlux = new EncryptionDecorator(compressedFlux);

            encryptedCompressedFlux.WriteData(Command.Serialize(command));
            List <object> parameters = new List <object>();

            parameters.Add("localhost");
            parameters.Add(8888);
            flux = new WebSocketSender().Send(flux, parameters);
            Console.WriteLine("Command result : " + BitConverter.ToInt32(flux.ReadData(), 0));
            Console.Write("Type any key to end the program");
            Console.ReadLine();
        }