This git Repository contains Example-Code used in the talk "Let's get Interdisciplinary - Rust Design Patterns for Chemical Plants" on RustNation UK 2024 (2024-03-28). Beside that, the Readme acts as a small handout/summary of the presentation.
- 1st Part: Rust Design Patterns - Builder & Type-State Pattern
- 2nd Part: Decomposing and Discussion of the Visitor Pattern
If you enjoyed the talk and want to checkout the mentioned additional materials:
- 1st Video - Pragmatic Rust for Engineers
- Blog Post - The Haber-Bosch Process: Revolutionizing Agriculture and Industry
“Design patterns are typical solutions to common problems in software design. Each pattern is like a blueprint that you can customize to solve a particular design problem in your code.” Refactoring Guru
The consist at least of a name, problem description and a solution. Often their relationships to other patterns and examples are given.
Historically they were introduced by the so-called gang of four (Eric Gamma, Richard, Helm, Ralph Johnson, John Vlissides) in the book "Design Patterns - Elements of Resuable Object-Oriented Software".
In my opinion: Design Patterns are useful for communication IF you questioning the common understanding. (Questioning the common understanding get's very important in interdisciplinary work-environments)
Chemical Plants are modeled as cyclic graph structure called flowsheet:
- Nodes represent so called unit operations, e.g. a reactor, a distillilation column, etc.
- Edges represent pipes for transporting liquids/gases, e.g. a mixture of Hydrogen, Nitrogen and Ammonia.
A distillation column is the most common seperation operation in the chemical industry.
- Problem: Complex Object with interdepending initialization of many fields
- Solution: Use a separate object responsible for the building
Very common in Rust due to the missing of function overloaded. Leads to a safe&ergonomic API.
- Problem: Object behavior is depending on a finite number of states
- Solution: Extract state-specific behavior for each state into own (internal) type
Recommended for Library code in Rust. Leads to a safe&ergonomic API backed by the compiler.
This pattern contains some interesting concepts, however it is easily misused because of it's complexity. Refer to the presentation to see the discussion.
- Problem: A (well-)defined object structure, shall support and might be extended with several algorithms
- Solution: Add a 2nd hierarchy that “visits” the objects to implement the algorithm for each object type
All the code is dual-licensed under either:
- MIT License
- Apache License, Version 2.0
at your option. This means you can select the license you prefer! This dual-licensing approach is the de-facto standard in the Rust ecosystem.