Skip to content

Commit 5826fb0

Browse files
docs: add immutability explanation to readme (#243)
1 parent da1109a commit 5826fb0

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ To send a request to the OpenAI API, build an instance of some `Params` class an
119119

120120
For example, `client.chat().completions().create(...)` should be called with an instance of `ChatCompletionCreateParams`, and it will return an instance of `ChatCompletion`.
121121

122+
## Immutability
123+
124+
Each class in the SDK has an associated [builder](https://blogs.oracle.com/javamagazine/post/exploring-joshua-blochs-builder-design-pattern-in-java) or factory method for constructing it.
125+
126+
Each class is [immutable](https://docs.oracle.com/javase/tutorial/essential/concurrency/immutable.html) once constructed. If the class has an associated builder, then it has a `toBuilder()` method, which can be used to convert it back to a builder for making a modified copy.
127+
128+
Because each class is immutable, builder modification will _never_ affect already built class instances.
129+
122130
## Asynchronous execution
123131

124132
The default client is synchronous. To switch to asynchronous execution, call the `async()` method:

0 commit comments

Comments
 (0)