官术网_书友最值得收藏!

Interfaces 

Open up the Interfaces folder and have a look at the IBatter.cs and IBowler.cs files. The IBatter interface looks as follows:

namespace cricketScoreTrack.Interfaces 
{ 
    interface IBatter 
    { 
        int BatsmanRuns { get; set; }         
        int BatsmanBallsFaced { get; set; }         
        int BatsmanMatch4s { get; set; }         
        int BatsmanMatch6s { get; set; }         
        double BatsmanBattingStrikeRate { get; }             
    } 
} 

Looking at the IBowler interface, you will see the following:

namespace cricketScoreTrack.Interfaces 
{ 
    interface IBowler 
    { 
        double BowlerSpeed { get; set; } 
        string BowlerType { get; set; }  
        int BowlerBallsBowled { get; set; } 
        int BowlerMaidens { get; set; }         
        int BowlerWickets { get; set; }         
        double BowlerStrikeRate { get; }         
        double BowlerEconomy { get; }  
        int BowlerRunsConceded { get; set; } 
        int BowlerOversBowled { get; set; } 
    } 
} 

An interface will only contain the signatures of methods, properties, events, or indexers. If we had to add a method to the interface to calculate the spin of the ball, it would look something like this:

void CalculateBallSpin(); 

On the implementation, we would see the code implemented as follows:

void CalculateBallSpin()
{
}

The next logical question would probably be what the difference is between an abstract class and an interface. Let's turn to the excellent Microsoft documentation at—https://docs.microsoft.com/en-us/.

After opening Microsoft Docs, try the dark theme. The theme toggle is to the right of the page, just below the Comments, Edit, and Share links. It's really great for us night owls.

Microsoft sums up an interface very nicely with the following statement:

An interface is like an abstract base class. Any class or struct that implements the interface must implement all its members.

Think of interfaces as verbs; that is to say, interfaces describe some sort of action. Something that a cricket player does. In this case, the actions are batting and bowling. The interfaces in Cricket Score Tracker are therefore IBatter and IBowler. Note that convention dictates that interfaces begin with the letter I.

Abstract classes on the other hand, act as a noun that tells you what something is. We have Batsmen and All-Rounders. We can say that both these cricketers are players. That is the common noun that describes the cricketers in a cricket match. Therefore, the Player abstract class makes sense here.

主站蜘蛛池模板: 本溪| 锡林浩特市| 保山市| 吴堡县| 阳原县| 包头市| 高碑店市| 贵溪市| 旌德县| 大安市| 喀喇沁旗| 县级市| 施秉县| 黔江区| 闸北区| 铁岭县| 藁城市| 吉木萨尔县| 潜江市| 徐汇区| 潞西市| 衡东县| 罗城| 石棉县| 调兵山市| 中卫市| 霞浦县| 大港区| 太康县| 镇沅| 邹城市| 拜城县| 页游| 仁怀市| 尚义县| 合肥市| 治县。| 望城县| 南昌市| 松溪县| 穆棱市|