← 返回 rippling 的题目列表Design a Logger with Configurable Message Processing (remove substring / truncate / uppercase / store-only)
类型:online_judge
Problem: Implement a Configurable Logger (OOD)
Implement a Logger that can process an input log message message according to a configured behavior, and then either print to stdout or store internally.
Supported behaviors:
Remove: remove all occurrences of a configured substring pattern before printing.
Truncate: truncate the message to at most maxLen characters before printing.
Uppercase: convert the entire message to uppercase before printing.
Store-only: do not print; store messages in an internal list.
Requirements
Use a reasonable OOD design (e.g., Strategy/Decorator/Chain of Responsibility) so that adding new behaviors requires minimal/no changes to existing code.
Provide a way to construct/configure the logger (constructor or factory), including needed parameters (e.g., pattern, maxLen).
For non-store behaviors, print the processed message to stdout.
For store-only, do not print; only store.
Examples
Remove(pattern="ab"), input "ab12ab3" -> prints "123"
Truncate(maxLen=4), input "hello" -> prints "hell"
Uppercase, input "Hello" -> prints "HELLO"
Store-only, input "hello" -> prints nothing; internal storage appends "hello"
Constraints
message contains printable ASCII characters.
pattern is non-empty.
maxLen >= 0.
Sample tests
Remove("ab") + ab12ab3 => stdout: 123
Truncate(4) + hello => stdout: hell
Uppercase + Hello, world! => stdout: HELLO, WORLD!
Store-only + msg1, msg2 => stdout: (none), stored: ["msg1","msg2"]
Truncate(0) + abc => stdout: ``
Example
Input
remove ab
ab12ab3
Output
123