设计模式:抽象工厂、代理与装饰器模式详解
1. 抽象工厂模式
抽象工厂模式是一种创建型设计模式,它提供了一种方式来封装一组具有共同主题的单个工厂的创建对象的方式。
1.1 实现示例
以下是一个使用抽象工厂模式创建动物对象的示例代码:
using System;
namespace AbstractFactoryPattern
{
public interface IDog
{
void Speak();
void Action();
}
public interface ITiger
{
void Speak();
void Action();
}
#region Wild Animal collections
class WildDog : IDog
{
public void Speak()
{
Console.WriteLine("Wild Dog says: Bow-Wow.");
}
public void Action()
{
Console.WriteLine("Wild Dogs prefer to roam freely in jungles.\n");
}
}
class WildTiger : ITiger
{
超级会员免费看
订阅专栏 解锁全文
9万+

被折叠的 条评论
为什么被折叠?



