5、tural example using System;using System.Collections;// "FlyweightFactory"class FlyweightFactory{ // Fields private Hashtable flyweights = new Hashtable(); // Constructors public FlyweightFactory() { flyweights.Add("X", new ConcreteFlyweight()); f
6、lyweights.Add("Y", new ConcreteFlyweight()); flyweights.Add("Z", new ConcreteFlyweight()); } // Methods文档实用 public Flyweight GetFlyweight(string key) { return((Flyweight)flyweights[ key ]); }}// "Flyweight"abstract class Flyweight{ // Methods ab
7、stract public void Operation( int extrinsicstate );}// "ConcreteFlyweight"class ConcreteFlyweight : Flyweight{ private string intrinsicstate = "A"; // Methods override public void Operation( int extrinsicstate ) { Console.WriteLine("ConcreteFlyweight:
8、 intrinsicstate {0}, extrinsicstate {1}", intrinsicstate, extrinsicstate );文档实用 }}/// /// Client test/// public class Client{ public static void Main( string[] args )