xxxVideo
public sealed class PornAdaptee
{
public void Watch(Guid videoId)
{
Console.WriteLine($"查看视频{videoId.ToString()}");
}
public void Download(Guid videoId)
{
Console.WriteLine($"下载视频{videoId.ToString()}");
}
}
public interface I91PornTarget
{
void Watch(Guid videoId);
void Download(Guid videoId);
}
public class Rank91PornAdapter : I91PornTarget
{
protected PornAdaptee PornAdaptee { get; }
public Rank91PornAdapter(PornAdaptee pornAdaptee)
{
PornAdaptee = pornAdaptee;
}
public void Watch(Guid videoId)
{
var d = new Random(2).Next(2);
if (d < 2)
{
Console.WriteLine("你是普通用户,看不了");
}
else
{
PornAdaptee.Watch(videoId);
}
}
public void Download(Guid videoId)
{
var d = new Random(2).Next(2);
if (d < 2)
{
Console.WriteLine("你是普通用户,下载不了");
}
else
{
PornAdaptee.Watch(videoId);
}
}
}
public class Vip91PornAdapter : I91PornTarget
{
protected PornAdaptee PornAdaptee { get; }
public Vip91PornAdapter(PornAdaptee pornAdaptee)
{
PornAdaptee = pornAdaptee;
}
public void Watch(Guid videoId)
{
{
PornAdaptee.Watch(videoId);
}
}
public void Download(Guid videoId)
{
{
PornAdaptee.Watch(videoId);
}
}
}
总结 :为某一个类做适配(不适合用抽象类)