随笔 - 53, 文章 - 0, 评论 - 3, 引用 - 0
数据加载中……

Throw away unnecessary interface!

Why we need Interface? The most important benefit come from the fact: The code depend on the interface no need to care about the implementaion class. and if the implementation class is changed later, the client code no need to update.
This is the feature of Ploymophism of OOP, such as Java. 

In some projects, the struts framework was adopted, so all the field need to be persisted is in ActionForm. In order to avoid that the Service layer /DAO layer will depends on the struts. One way is to define a interface which have getter and
setter to access all the fields need to be persisted. The design is like this:

XXXActionForm --------> XXXInterface <--------------ServiceLayer/DAO Layer
                                          most of them are 
                                          getter and setter
 
I can understand this concern, it seems follow the paterns in Enterprise Application Architecture Pattern. but I can not agree this kinds of design. I believe this is misuse of interface.

First, in this kinds of design, if we add some fields, we need update the actionForm, them also need to update interface.
It is boring, and in this case, the interface can not provide any abstraction so the interface need to evolve as the implementation changed.

Second, there is only one  kind of implementaion in the system, so the interface can not provide the benifit from making use of polymorphism.

In a word, we can get nothing design benefit from Interface in this case, And Have burden to keep the implementaion and interface synchronized.

posted on 2006-02-19 17:30 InPractice 阅读(276) 评论(0)  编辑  收藏 所属分类: Java


只有注册用户登录后才能发表评论。


网站导航: