Revisiting Design Patterns after 20
Conference (INTERMEDIATE level)
Room 3
Score 0.15
Score 0.17
Score 0.18
Score 0.18
The match becomes increasingly accurate as the similarity score approaches zero.
In 1994, the Gang of Four brought to us 23 different design patterns that helped thousands, maybe millions of developers, to design better code and share a common language. Almost three decades later, improvements in the Java language allow us to revisit most of these design patterns and propose novel ways to solve the same problems.
Join us at this talk when we perform some live refactorings of code using legacy implementations of design patterns into new code using the latest improvements of Java 20. Come and witness how Strategy, Template Method, Visitor, Command, Decorator, Builder, and other patterns can significantly benefit from modern features of Java, such as lambdas, records, switch expressions, and much more.
Generated Summary
WARNING: This summary was generated using GPT based on the transcript, as a result spelling mistakes and more importantly hallucinations can be present.
Revisiting Design Patterns After 20 Years
Overview
Edson Yanaga, a Developer Relations Engineer for Google Wallets, is presenting a talk about revisiting design patterns after 20 years. He recommends adding Google Wallet passes to phones to make the registration process easier and faster. He will discuss the original idea of design patterns from a 1994 book and best practices from the Effective Java book. He will also demonstrate some features of the upcoming Java 20 release on March 21st. There will also be a raffle at the end of the session with prizes such as Pixel Buds Pro or Google Nest audio. Design Patterns
Design patterns are general, reusable solutions to commonly occurring problems in a given context. They allow developers to create a pattern language which improves discussions around code design. Common guiding principles for solutions include favoring composition over inheritance, smaller interfaces and existing interfaces. An example of a design pattern is the strategy pattern which is used to generate links for Google Wallet. This text discusses two different ways of creating a link for Google Wallet. The first is to create a complete JWT containing all the relevant information, while the second is to pre-create data and reference it in the JWT that is sent to the user. The code looks similar, but one method creates an interface while the other uses a function. Legacy template methods can also be used, but they can be replaced with strategy. Evolution of Programming Languages
This article discusses the evolution of programming languages from structured programming to object-oriented programming. It explains that when invoking code in structured programming, one must pass the state of the system and other contextual information as parameters. In object-oriented programming, the state is embedded in the type being called and the method name is preceded by the type. This is known as single dispatch, where the instructions executed by the computer depend on the type being referred to. Strategy Pattern
The strategy discussed is a single dispatch decision which chooses which code to execute based on the type of object passed in. This article explains how to use the visitor pattern to secure code that depends on both the type of object being called and the type being called. It is demonstrated through an example of creating Google Wallet passes, which can be either loyalty cards or event tickets and either complete or brief versions. The visitor pattern is useful for keeping related objects and operations close together, making the code more readable and maintainable. It can also be combined with other patterns to further improve the code. Visitor is a design pattern that can be used to make code more efficient. It can help to avoid runtime errors by breaking at compile time if there is a need to add another method to visits. Java 20
With Java 20, better matching can be used instead of having to create a separate class for the visitor, and switch statements can be used to choose the code that will be executed based on the type of objects. This new feature of pattern matching in Java 20 provides a more efficient way to code. Additional Patterns
This article discusses the use of double dispatching, legacy Singleton, and Chain of Responsibility patterns in software development. Double dispatching allows for properties of an object to be taken into consideration when deciding what action to take. Legacy Singleton is a pattern where a private static final property is created, and lazy initialization can be used. Chain of Responsibility is a pattern where an interface is created with two methods and an abstract class which knows the next step. This can be implemented with either predicates and consumers in a Lambda, or a record with two properties. Conclusion
This talk discussed how to use specifications, predicates, and other code to create queries that can be reused across a system. It was suggested that instead of creating a new implementation of specifications, predicates from the JDK should be used as they offer more operations and are more complete. At the end of the talk, a raffle was held where one of two prizes was given away. The number of rows and seats in the theater were counted and used to generate a random number to determine the winner. In conclusion, Edson Yanaga discussed the evolution of programming language and design patterns, best practices, and features of the upcoming Java 20 release. He also demonstrated how to create queries using specifications, predicates, and other code and how to use the visitor pattern, double dispatching, legacy Singleton and Chain of Responsibility patterns in software development.You can also ask questions on the complete talk using Devoxx Insights