策略者模式:根据不同的输入得到不同种类的输出结果。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AbsBase
{
public float salary;
public virtual void CaculateTax()
{
}
}
public class AbsPerson : AbsBase
{
public override void CaculateTax()
{
salary *= 0.08f;
}
}
public class AbsCompany : AbsBase
{
public override void CaculateTax()
{
salary *= 0.12f;
}
}
public class TestAbstrator : MonoBehaviour
{
public void CaculateTax(AbsBase tmpBase)
{
tmpBase.CaculateTax();
}
// Start is called before the first frame update
void Start()
{
AbsPerson tmpPerson = new AbsPerson();
CaculateTax(tmpPerson);//多态
AbsCompany tmpCompany = new AbsCompany();
CaculateTax(tmpCompany);
}
// Update is called once per frame
void Update()
{
}
}
A——>C——>D