开发者

Using interfaces between layers [closed]

Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

开发者_如何学运维

Closed 11 years ago.

Improve this question

Should communication between layers always be done using an interface or is it OK to access objects directly?

For example between the business logic and business object layers/projects.


Accessing objects directly creates very tight coupling between objects - "what do you mean, you refactored Customer.FirstName to Customer.Name.GivenName? Now I have to rewrite my code, oh noes!"

Programming against an interface gives you more power to change the implementation later on, perhaps swap in a completely new one (even dynamically, at runtime). It may seem like bother, but for anything bigger than Hello World, tight coupling will come back to bite you in the butt (or whomever that maintains the code after the guy who maintained it after you).


There are many advantages of using interface. You would do better to read up a good book on principles of object oriented technology. Or just search for why use interfaces. But the short answer is use interfaces.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜