Learning to use Interfaces effectively

后端 未结 2 1855
小蘑菇
小蘑菇 2020-12-07 11:13

I\'ve been developing software in C# for a while, but one major area that I don\'t use effectively enough is interfaces. In fact, I\'m often confused on the various ways the

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 11:49

    Interfaces are generally used to force implementing classes to obey a certain contract (meaning to have certain methods). Sometimes they are just used as markers i.e. they have no methods declared but enable some code generator to generate special code for the implementing class.

    Having said this, interfaces are not really a "tool" in their own right, so they don't serve a particular functional purpose, but they can greatly simplify the design of your application and are used extensively in OO design patterns. A basic resource is this tutorial: http://www.csharp-station.com/Tutorial/CSharp/Lesson13

提交回复
热议问题