Multiple Interface Inheritance


Just as classes can implement multiple interfaces, interfaces can inherit from multiple interfaces, and the syntax is consistent with class derivation and implementation, as shown in Listing 7.9.

Listing 7.9. Multiple Interface Inheritance

 interface IReadableSettingsProvider {   string GetSetting(string name, string defaultValue); } interface IWriteableSettingsProvider {   void SetSetting(string name, string value); } interface ISettingsProvider : IReadableSettingsProvider,     IWriteableSettingsProvider                                  { } 

It is unusual to have an interface with no members, but if implementing both interfaces together is predominant, it is a reasonable choice for this case. The difference between Listing 7.9 and Listing 7.6 is that it is now possible to implement IWriteableSettingsProvider without supplying any read capability. Listing 7.6's FileSettingsProvider is unaffected, but if it used explicit member implementation, specifying which interface a member belongs to changes slightly.




Essential C# 2.0
Essential C# 2.0
ISBN: 0321150775
EAN: 2147483647
Year: 2007
Pages: 185

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net