I read about this in Agile Principles, Patterns, and Practices in C#, the author - Robert Martin says that if you use the "I" prefix for interfaces then you might run into problem if you later decide to change the interface to an abstract class.
In which case you cannot continue to use the "I" prefix name, so you will have to rename it wherever you have referenced it - so, you should not use the prefix.
Microsoft seems to have ignored this issue, they want a interface/class pair to be distinguished but the letter "I" for the interface : http://msdn.microsoft.com/en-us/library/ms229040.aspx
Monday, April 13, 2009
Wednesday, April 08, 2009
C# Properties
There are 2 types of properties :
Why should we excapsulate access to field?
But there are some disadvantages with this :
you have to write a method and users have to call that method.
Another way is to use properties : they can be static, instance, abstract, virtual, with any access specifier, with an interface, however they cannot be overloaded and they cannot have void return type
Properties compile down to methods.
Why not to use Properties :
Because as against fields they break the following assumptions:
Cannot have static indexers
- parameterless - normal properties
- parameterful - indexers
Why should we excapsulate access to field?
- execute some side effect
- cache some value
- lazily create some internal object
- access in thread safe way
- return value which needs to be calculated on fly
But there are some disadvantages with this :
you have to write a method and users have to call that method.
Another way is to use properties : they can be static, instance, abstract, virtual, with any access specifier, with an interface, however they cannot be overloaded and they cannot have void return type
Properties compile down to methods.
Why not to use Properties :
Because as against fields they break the following assumptions:
- fields are always read and write, not properties
- fields never throw exception
- fields can be passed as out or ref
- field access completes immediately
- field always return same value
- field never has side-effects
- field always works on original object.
Cannot have static indexers
Subscribe to:
Posts (Atom)