A bad pattern - temporal decomposition
Take away
Design modules based on the knowledge needed for each task, not the order of operations, to prevent information leakage.
Way
temporal decomposition is a bad design style where the structure of a system is organized based on the sequence of operations that occurs over time. Essentially, it's dividing the system into parts that correspond to the steps in a process, in the order they happen.
Examples - file read and write
an application that:
- reads a file in a particular format
- modifies the contents of the file
- then writes the file out again.
which results to information leakage .
Q: Why ?
A: Both the file reading and writing components need to know the file format. This shared knowledge about the file format between different classes
Examples - an e-commerce example
an application that:
order processor
- take an order from a customer.- It knows about the order detailed and how to calculate the total price.
payment gateway
- handles the payment processing.- It receives the order total from
order processor
and interacts with a payment gateway to complete the transaction.
- It receives the order total from
order confirm to sender
- sends a confirmation email to customer after the payment is success.- it receives the order detailed from
order processor
- it receives the order detailed from
both order processor
and order confirm to sender
know about the payment detail, which tightly coupling them that it's hard to modify or extend
Recommendations
- Avoid the design style of temporal decomposition to prevent information leakage.
- Combine the core mechanism for related tasks into a single class to promote information hiding.