zoukankan      html  css  js  c++  java
  • Interface Key Note

    Interface Key Notes (MSDN Interface)
    1. Explicit Interface Implementation
    There are 2: implicit and explicit interface implementation. Implicit type is normal to be used. Here, to understand more about why needs explicit interface implementation, give 2 reasons got from
    Unleashed C#:
        --Hide interface method / event / property / indexer in case to direct use the derived class.
        --There are same signature functions in the derived class's parent interfaces, so it needs things like IBroker.GetRating and IAdviser.GetRating explicitly to get two implementations.

    "Sometimes it’s necessary to explicitly declare which interface a class or struct member implements. One common reason for explicit implementation is when there is multiple interface inheritance and two or more interfaces declare a member with the same name.
    Another reason to use explicit interface implementation is to hide a specific implementation.
    To perform explicit interface implementation, a class implements an interface member by using its fully qualified name. The implementation is not declared with modifiers, because
    they are implicitly hidden from an object of the implementing class. However, they are implicitly visible to objects of the explicit interface type."

    2. Interface Mapping.
    public class Accountant : StockBroker, IBroker
    {
    // no implementation
    }
    If StockBroker's implementation matchs IBroker's requirement, the Accountant class won't require any implementation to get compiler believe it's correct! This is interface mapping in C#!

    This is because with C# interface mapping, the implementation of the StockBroker class is used to map to the implementation requirements of the IBroker interface.

    3. Can Add Virtual in derived class of the interfaces

    Normally, we don't need to add virtual keyword in the derived class of interfaces. But there are cases we need to add virtual to enable the derived class's children can override some behaviors. From MSDN: "It is possible for a base class to implement interface members using virtual members; in that case, the class inheriting the interface can change the interface behavior by overriding the virtual members."

  • 相关阅读:
    hdu4578 (多标记线段树)
    hdu4757 (可持久化字典树+LCA)
    CF940F Machine Learning (带修改莫队)
    csps模拟测试7576一句话题解
    csps模拟测试74梦境,玩具,飘雪圣域题解
    csps模拟测试7273简单的操作小P的2048小P的单调数列小P的生成树
    csps模拟测试707172部分题解myc
    莫队算法学习
    csps模拟69chess,array,70木板,打扫卫生题解
    csps模拟68d,e,f题解
  • 原文地址:https://www.cnblogs.com/taoxu0903/p/1732583.html
Copyright © 2011-2022 走看看