包组织和项目结构设计

Package organization and project structure design

我正在尝试在 java 中创建一个 textsearcher 库,它将有一个接口 TextSearcher 和 3 个 class 实现它:RegexPatternSearcher , SingleTokenSearcherMultiTokenSearcher

然后我创建了一个 TextSearcherFacade class 公开了 static 方法,例如:

  1. static findEmailAddresses(String input) - 使用 RegexPatternSearcher
  2. static findPhoneNumbers(String input) - 使用 RegexPatternSearcher
  3. static findDisallowedWords(String input, Set<String> disAllowedWords) - 使用 SingleTokenSearcher

我希望库的用户公开这些(即 TextSearcherFacade 中的方法)简单方法以便于使用。

但是,我不喜欢使用配置和创建 RegexPatternSearcherSingleTokenSearcher 和 [=14= 的方法的单个 TextSearcherFacade class 的想法] 因为这些方法依赖于不同的 classes 并且在逻辑上看起来不同。

我正在尝试寻找一种更好、更可扩展的方法来设计这个库。非常感谢任何帮助。

您可以为每个查找方法创建一个 class。例如,您可以设置 EmailFinderPhoneNumberFinder

此外,他们可以使用 List<FindResult> find(String input) 方法实现 interface,您可以通过实例化它们并调用 find() 方法来使用它们。