Recommendation 96: Members should prioritize exposing base types or interfaces
Type members will allow the type to support more applications if the public and the type or interface are given precedence.
The most typical example in the FCL is the functional operation of the collection. The set is divided into several types according to function, such as list<t>, dictionary<tkey,tvalue>, hashset<t>, etc. Take one of the simplest operations of empty (emptying the collection) as an example. This feature requires that we delete all the elements in the collection and then return a clean collection. If you do not return a base type or interface, you are required to implement one of these methods for each collection type.
Microsoft implemented such a static type enumerable in the FCL, which has a static method:
Public Static Ienumerable<tresult> empty<tresult>() { return emptyenumerable<tresult> . Instance; }
Because the generic interface IEnumerable is used, all of the collection subclasses can now implement their own empty method. We should appreciate the benefits of this programming model and use it flexibly in our own projects.
Turn from: 157 recommendations for writing high-quality code to improve C # programs Minjia
"Go" writing high-quality Code 157 recommendations for improving C # programs--recommendation 96: Members should prioritize exposing base types or interfaces