One of the 70-565 exam topics is Designing and Developing an Application Framework and it looks like 25% of all questions are about designing and developing an application framework. If to read what the topic covers, you find that there are questions about defining the interaction between framework components, which is defining data APIs, security APIs, abstract classes, class interfaces, and data contracts. There's been plenty of posts and discussion whether to use interfaces or abstract classes, but I noticed that there isn't enough with regard to implementing an interface, which is whether an interface should be implemented implicitely or explicitely. Those are two choices presented by IntelliSense to implement an interface as shown below.
[Rules.cs]
NameRule class implicitely implements IRule interface whereas EmailRule does explicit implementation. You can see the difference in the signature of the Evalute method - in NameRule class method is public, in EmailRule class public modified is not valid, hence it is not there plus method name is preceded by interface name - IRule. This difference results in the following limitations within a class that implements an interface explicitely:
- interface method/property is not accessible from the class object as it were private. In the example above, rule object of type EmailRule cannot call Evaluate method, but has to be cast to the interface type first: (rule as IRule).Evaluate
- interface method/property cannot be abstract or virtual, which means that a class that explicitely implements an interface must provide the implemention of the method and that implemention cannot be overriden or marked as abstract so it can be provided by classes that inherit from the abstract class
0 comments: