清理我的Java项目的架构实践

时间:2016-01-19 09:24:49

标签: java oop interface architecture

我想问一下,如果您有任何想法,可以使我的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;
   }
   }

提前感谢您的建议。

2 个答案:

答案 0 :(得分:1)

这种模式是一种常见且可接受的模式 - 甚至可以在Java库中使用。见extends implements ArrayListException ignored in: <bound method Connection.__del__ of <aiomysql.connection.Connection object at 0x00000030F8080B38>> Traceback (most recent call last): File "C:\software\development\python3.5\lib\site-packages\aiomysql\connection.py", line 689, in __del__ File "C:\software\development\python3.5\lib\site-packages\aiomysql\connection.py", line 261, in close File "C:\software\development\python3.5\lib\asyncio\selector_events.py", line 569, in close File "C:\software\development\python3.5\lib\asyncio\base_events.py", line 447, in call_soon File "C:\software\development\python3.5\lib\asyncio\base_events.py", line 456, in _call_soon File "C:\software\development\python3.5\lib\asyncio\base_events.py", line 284, in _check_closed RuntimeError: Event loop is closed AbstractList {/ 3}}。

答案 1 :(得分:1)

您可以尝试以下操作:

  1. 使用Strategy Pattern代替Template Method - 使用合成优于继承更好。
  2. 你应该通过RdfDataChecker类找出是否有可能将一些代码提取到不同的类。
  3. 将列表数据设为私有 - 每个类都应封装自己的字段。