Function that Returns an Interface RRS feed

  • Question

  • Hi all

    while studying a examplen  C# code I found this code

    internal ArrayList ArrayListOfAllRows;

    internal IList Fill() { //// code that fills an ArrayList ..... ..... return ArrayListOfAllRows; }

    I do understand the fact that the Function Fill   returns  an Interface (IList)

    What does it mean ?

    Thanks for help

    Friday, September 14, 2018 6:24 AM


  • This is done to expose the minimum functionality that can be used by the callers of the function. By returning an interface instead of returning the class that implements the interface, we are free to change the internal implementation of the function and maybe use a more suitable class internally. The callers of the function will not be affected, since we know that they can only be calling the members of the interface, and they won't be using any other functionality of the ArrayList, since the ArrayList was hidden from them.
    • Marked as answer by Claudio111 Friday, September 14, 2018 7:48 AM
    Friday, September 14, 2018 6:41 AM