kirktrue commented on PR #15750: URL: https://github.com/apache/kafka/pull/15750#issuecomment-2065387420
We've been encouraged to follow the pattern of having the super class implement `toString()` and add a `toStringBase()`, like this: ```java public class Parent { private final String foo = "Hello, world!"; protected String toStringBase() { return "foo=" + foo; } @Override public String toString() { return getClass().getSimpleName() + "{" + toStringBase() + "}"; } } ``` Then the subclasses would implement `toStringBase()` to add their values: ```java public class Child extends Parent { private final String bar = "Many"; private final String baz = "Few"; @Override protected String toStringBase() { return super.toStringBase() + ", bar=" + bar + ", baz=" + bad; } } ``` The rationale I was given was: 1. It allows the parent to keep its state private, but still "expose" it via `toString()` 2. It helps to ensure the correct class name appears in the output 3. It keeps the output uniform and reminds the developer to keep the parent state I'm not crazy about the design idiom, but that's what we were asked to use. It works OK as long as it's applied uniformly. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org