程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 設計模式(C#) - 抽象工廠模式(Abstract Factory Pattern)(4)

設計模式(C#) - 抽象工廠模式(Abstract Factory Pattern)(4)

編輯:關於C語言

SqlMessage

using System;
using System.Collections.Generic;
using System.Text;

namespace Pattern.AbstractFactory
{
  /**//// <summary>
  /// Sql方式操作Message類(Product)
  /// </summary>
  public class SqlMessage : AbstractMessage
  {
    /**//// <summary>
    /// 插入Message
    /// </summary>
    /// <param name="amm">AbstractMessageModel</param>
    /// <returns></returns>
    public override string Insert(AbstractMessageModel amm)
    {
      return "Sql方式插入Message。帳號:" + amm.UserId
        + ";內容:" + amm.Message
        + ";時間:" + amm.PublishTime.ToString();
    }
  }
}

XMLMessage

using System;
using System.Collections.Generic;
using System.Text;

namespace Pattern.AbstractFactory
{
  /**//// <summary>
  /// XML方式操作Message類(Product)
  /// </summary>
  public class XMLMessage : AbstractMessage
  {
    /**//// <summary>
    /// 插入Message
    /// </summary>
    /// <param name="amm">AbstractMessageModel</param>
    /// <returns></returns>
    public override string Insert(AbstractMessageModel amm)
    {
      return "XML方式插入Message。帳號:" + amm.UserId
        + ";內容:" + amm.Message
        + ";時間:" + amm.PublishTime.ToString();
    }
  }
}

AbstractMessageFactory

using System;
using System.Collections.Generic;
using System.Text;

namespace Pattern.AbstractFactory
{
  /**//// <summary>
  /// 抽象Message工廠(AbstractFactory)
  /// </summary>
  public abstract class AbstractMessageFactory
  {
    /**//// <summary>
    /// 創建MessageModel對象
    /// </summary>
    /// <returns></returns>
    public abstract AbstractMessageModel CreateMessageModel();

    /**//// <summary>
    /// 創建Message對象
    /// </summary>
    /// <returns></returns>
    public abstract AbstractMessage CreateMessage();
  }
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved