zoukankan      html  css  js  c++  java
  • flyweighttheoryns.cs

      using System;
      using System.Collections.Generic;
      using System.Drawing;
      using System.Windows.Forms;

      namespace FlyweightPattern {

        // Flyweight Pattern        Judith Bishop  Sept 07
        // Defined for state which is images
     
        // IFlyweight Interface
        public interface IFlyweight {
          void Load (string filename);
          void Display (PaintEventArgs e, int row, int col);
        }

        // Flyweight
        public struct Flyweight : IFlyweight {
          // Intrinsicstate
          Image pThumbnail;
          public void Load (string filename) {
            pThumbnail = new Bitmap("images/"+filename).
                               GetThumbnailImage(100, 100, null, new IntPtr());
          }

          public void Display(PaintEventArgs e, int row, int col) {
            // Calculating extrinsic state
            e.Graphics.DrawImage(pThumbnail,col*100+10, row*130+40,
                                           pThumbnail.Width,pThumbnail.Height);
          }
        }

        public class FlyweightFactory {
          // Keeps an indexed list of IFlyweight objects in existance
          Dictionary <string,IFlyweight> flyweights =
              new Dictionary <string,IFlyweight> ();

          public FlyweightFactory () {
            flyweights.Clear();
          }

          public IFlyweight this[string index] {   
            get {  
              if (!flyweights.ContainsKey(index))
                  flyweights[index] = new Flyweight();
              return flyweights[index];
            }  
          }
        }
      }
  • 相关阅读:
    Spring配置文件中别名的使用
    Spring IOC容器创建对象的方式
    sass安装及使用
    word转html 压缩图片网站
    Yarn 和 Npm 命令行切换 摘录
    react生命周期
    event事件
    Flex 布局
    YYYY-mm-dd HH:MM:SS 时间格式
    页面按钮埋点+跟踪location.search
  • 原文地址:https://www.cnblogs.com/shihao/p/2496413.html
Copyright © 2011-2022 走看看