Prefer builder pattern to setters/getters in KeywordExtractConfig
awong-dev opened this issue · 3 comments
awong-dev commented
Fromt here https://github.com/messense/jieba-rs/pull/100/files#r1560432915
@messense said
I'd remove getters (not really useful) and use builder pattern for KeywordExtractConfig, like
let config = KeywordExtractConfig::builder() .add_stop_word("word") .use_hmm(true) // and other options .build();
or without a separate builder type:
let config = KeywordExtractConfig::default() .add_stop_word("word") .use_hmm(true) // and other options ;
The builder pattern is indeed nicer here. The getters may still be wanted to allow other languages to query the rust struct w/o replicating the state...but builder does seem like a definite win.
messense commented
It's fine to keep getters, in that case a separate builder type is better so we don't need to name getters get_XXX()
, just use XXX()
like let use_hmm = config.use_hmm();
messense commented
awong-dev commented
Gotcha. Will look into it. Need to sleep for now. :)