我的 Java 项目的干净架构实践

Clean architecture practice for my Java project

我想问一下,如果您有任何想法,可以使我的 Java 项目的架构更简洁。

  abstract class rdfDataChecker {
    List<T> data;
    // all abstract methods to check data... more than 20 methods. They all use the list "data". 
    }

    // the idea of this interface is, that all the data loaders can just use feedable.feed(List<T>). (we inject this dataChecker to the data Loader).
    interface Feedable {
    void feed(List<T>);
    }

   //implementations in different java frameworks.
    class specificRdfDataChecker extends rdfDataChecker implements Feedable{
    // implement all the methods.
    }


   class DataLoader {
   private Feedable feedable;
   public DataLoader(Feedable feedable) { 
   this.feedable = feedable;
   }
   }

提前感谢您的建议。

此模式是一种常见且可接受的模式 - 它甚至在 Java 库中使用。参见 ArrayList that extends AbstractList and implements List

您可以尝试以下操作:

  1. 使用 Strategy Pattern instead of Template Method - 使用组合总是比继承更好。
  2. 您应该检查 RdfDataChecker class 并找出是否可以将一些代码提取到不同的 class。
  3. 将列表数据设为私有 - 每个 class 都应封装自己的字段。