From the course: Java Design Patterns: Behavioral Part 2

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Improving the Strategy pattern with Java 8 features

Improving the Strategy pattern with Java 8 features - Java Tutorial

From the course: Java Design Patterns: Behavioral Part 2

Start my 1-month free trial

Improving the Strategy pattern with Java 8 features

- [Instructor] So now I've created my file encryption app, which uses the strategy pattern to make sure it's simple and maintainable. But there are still ways I could improve it using some of the newer features of Java. You might have noticed that the encryptor interface is actually a functional interface, because it contains a single unimplemented method. So instead of creating concrete implementations of it, I could use the Java eight's Lambda feature instead. For example, if I go to the main class, instead of creating this new AESEncryptor object, I could replace this with a Lambda. So I could delete this, and instead have a pair of brackets and an arrow, and the string, applying AES encryption. And I also need to change this to an encryptor object instead of AES Encryptor. If I rerun the app now, I can see I still get the same outputs as before. It still says, applying AES encryption to test dot pdf. I could then go ahead…

Contents