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."); }
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. }