Using interfaces between layers [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
开发者_如何学运维Closed 11 years ago.
Improve this questionShould 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.
精彩评论