All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
asp.net回车键执行相应按钮事件的代码_[Asp.Net教程]
系统恢复后,通过sqlserver服务管理器启动出现“指定的服务未安装”的解决方法_[SQL,Server教程]
动态网页制作PHP入门:PHP是什么?_php资料_编程技术
xhtml+css网页制作教程_[Html教程]
C#入门代码_[Asp.Net教程]
几个比较有用的正则表达式_php资料_编程技术
详解ASP.NET数据读取与填充方式_[Asp.Net教程]
ASP.NET中Multi——ListBox控件编程详解_.net资料_编程技术
在PHP的图形函数中显示汉字_php资料_编程技术
33条C#、.Net经典面试题目及答案_[Asp.Net教程]
Reading number is top 10 pictures
俄罗斯台球天后惊艳魅惑2
Ashlynn Brooke photograph of a group3
运动的范冰冰1
The money of more than 100 countries and regions10
A man's favorite things9
HongMenYan premiere XinLiangGong clairvoyant outfit PK YiFeiLiu1
NeedWallpaper5
The little girl with long hair2
Small s breast enhancement demonstration
乳娘帕梅拉安德森3
Download software ranking
Twenty piece of palm leaf
Unix video tutorial8
Ashlynn Video3
Unix video tutorial9
Unix video tutorial5
塘西风月痕
双旗镇刀客B
虚拟机汉化软件
美女写真3
致我们终将逝去的青春
aaa published in(发表于) 2013/12/18 8:20:00 Edit(编辑)
无废话C#设计模式之三:Abstract,Factory_.net资料_编程技术

无废话C#设计模式之三:Abstract,Factory_.net资料_编程技术

无废话C#设计模式之三:Abstract Factory_.net资料_编程技术-你的首页-uuhomepage.com

  本系列文章将向大家介绍一下C#的设计模式,此为第三篇文章,相信对大家会有所帮助的。废话不多说,继续来看。


  意图


  提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类。


  场景


  还是上次说的那个网络游戏,定下来是一个休闲的FPS游戏。和CS差不多,8到16个玩家在游戏里面分成2组对战射击。现在要实现初始化场景的工作。要呈现一个三维物体一般两个元素是少不了的,一是这个物体的骨架,也就是模型,二就是这个骨架上填充的纹理。


  我们知道,这样的一个游戏不可能只有一张地图,而且地图的数量肯定是会一直增加的。如果游戏在初始化场景的时候需要根据不同的地图分别加载模型和纹理对象,那么势必就会使得场景的扩充变得很不方便。由此,我们引入Abstract Factory,抽象工厂生产的都是实际类型的接口(或者抽象类型),如果加了新的场景可以确保不需要修改加载场景的那部分代码。


  示例代码



  using System;
  using System.Reflection;
  namespace AbstractFactoryExample
  {
  class Program
  {
  static void Main(string[] args)
  {
  Patrix patrix = new Patrix();
  patrix.LoadScene("HalfPaper");
  patrix.LoadScene("Matrix");
  }
  }
  class Patrix
  {
  private PatrixSceneFactory GetGameScene(string gameSceneName)
  {
  return (PatrixSceneFactory)Assembly.Load("AbstractFactoryExample").CreateInstance("AbstractFactoryExample." + gameSceneName);
  }
  public void LoadScene(string gameSceneName)
  {
  PatrixSceneFactory psf = GetGameScene(gameSceneName);
  Texture texture = psf.CreateTexture();
  Model model = psf.CreateModel();
  model.FillTexture(texture);
  }
  }
  abstract class PatrixSceneFactory
  {
  public abstract Model CreateModel();
  public abstract Texture CreateTexture();
  }
  abstract class Model
  {
  public abstract void FillTexture(Texture texture);
  }
  abstract class Texture
  {
  }
  class HalfPaper : PatrixSceneFactory
  {
  public override Model CreateModel()
  {
  return new HalfPaperModel();
  }
  public override Texture CreateTexture()
  {
  return new HalfPaperTexture();
  }
  }
  class HalfPaperModel : Model
  {
  public HalfPaperModel()
  {
  Console.WriteLine("HalfPaper Model Created");
  }
  public override void FillTexture(Texture texture)
  {
  Console.WriteLine("HalfPaper Model is filled Texture");
  }
  }
  class HalfPaperTexture : Texture
  {
  public HalfPaperTexture()
  {
  Console.WriteLine("HalfPaper Texture Created");
  }
  }
  class Matrix : PatrixSceneFactory
  {
  public override Model CreateModel()
  {
  return new MatrixModel();
  }
  public override Texture CreateTexture()
  {
  return new MatrixTexture();
  }
  }
  class MatrixModel : Model
  {
  public MatrixModel()
  {
  Console.WriteLine("Matrix Model Created");
  }
  public override void FillTexture(Texture texture)
  {
  Console.WriteLine("Matrix Model is filled Texture");
  }
  }
  class MatrixTexture : Texture
  {
  public MatrixTexture()
  {
  Console.WriteLine("Matrix Texture Created");
  }
  }
  }



添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.