How to use the Strategy Pattern with C#?

前端 未结 7 765
暗喜
暗喜 2021-01-01 18:29

Here\'s what I have so far:

namespace Strategy
{
    interface IWeaponBehavior
    {
        void UseWeapon();
    }
}

namespace Strategy
{
    class Knife          


        
7条回答
  •  天涯浪人
    2021-01-01 19:01

    public class Character
    {
        IWeaponBehavior Weapon;
    }
    
    public class Princess : Character
    {
        Weapon = new Pan();
    }
    
    public class Thief : Character
    {
        Weapon = new Knife();
    }
    

提交回复
热议问题