-
Book Overview & Buying
-
Table Of Contents
Design Patterns and Best Practices in Rust
By :
The Template Method pattern provides a way to standardize algorithms while allowing customization of specific steps. It defines the skeleton of an algorithm in a base type, deferring some steps to subtypes. This enables code reuse for common algorithm steps while allowing specific implementations to vary.
Our calculator has grown sophisticated through each pattern we've implemented. We now have components that process expressions in similar but slightly different ways: standard arithmetic uses basic operators, scientific mode adds trigonometric functions, and programmer mode handles different number bases.
Despite these differences, all expression evaluation follows a common sequence: