13. EmployeeList l = FillList(); for (int i = 0; i < l.Length; i++){ if (l.All[i] == x){...} } public Employee[] All {get{}} Moral: Use method if the operation is expensive Calling Code Properties and returning arrays
15. CONSIDER using extension methods to "add" methods to interfaces
16. CONSIDER using extension methods to manage dependencies Uri uri = “ftp://some.ftp.uri”.ToUri(); // higher level assembly (not mscorlib) namespace System.Net { public static class StringExtensions{ public static Uri ToUri(this string s){ … } } }
17.
18. AVOID defining extension methods on System.Object
38. Inversion of Control // your better API public abstract class TraceListener { public abstract void Trace(string message); } public class Tracer { TraceListener listener; public Tracer( TraceListener listener ){ this.listener = listener; } public void Trace(string message){ listener.Trace(message); } }
39. Dependency Injection Check Containers like: Spring.NET, Castle Windsor , Structuremap, , Unity … MEF session tomorrow will talk about it (isA)