- Hits: 1820
Welcome to appthem - and to quality software development.
This website contains useful links and articles which will assist you in writing readable and maintainable code.
"Write code as if it will be maintained by a homicidal maniac who knows where you live" is a good mantra to code by. Please consider future developers who have to maintain your code.
- Hits: 2876
- Hits: 1700
Why pass collections as their interfaces? (soliD)
Give careful consideration to how you pass around collections. Try not to tie parameters and return values to their implementation classes. Specify them as interfaces and release your code from this dependency.
When passing parameters, always select the most primitive interface, eg.
If your collection parameter is going to be read in order (it’s only used in a foreach or otherwise doesn’t need random access), pass it as IEnumerable<T>.
If your collection parameter will be changed or needs random access, pass it as ICollection<T>.
Why? You’re removing the dependency and you’re also making your method more flexible giving the caller the ability to pass any kind of collection which implements that interface.
- Hits: 1947
SOLID is an acronym for a collection of design principles used to create good code. It was coined by Robert C. Martin in 2003 in "Principles of OOD". It's as relevant today as it was in 2003, and many great software developers use these principles, even if they have forgotten their names. The main thing to remember is to avoid tightly coupling your code.