public Flyweight GetByKey(char key) { // Uses "lazy initialization" Flyweight valueByKay = null; if (_initialized.ContainsKey(key)) { valueByKay = _initialized[key]; } else { switch (key) { case 'A': valueByKay = new FlyweightForAImpl(); break; case 'B': valueByKay = new FlyweightForBImpl(); break; //... case 'Z': valueByKay = new FlyweightForZImpl(); break; } _initialized.Add(key, valueByKay); } return valueByKay; }
public Flyweight GetByKey(char key) { // Uses "lazy initialization" Flyweight valueByKay = null; if (_initialized.ContainsKey(key)) { valueByKay = _initialized[key]; } else { switch (key) { case 'A': valueByKay = new FlyweightForAImpl(); break; case 'B': valueByKay = new FlyweightForBImpl(); break; //... case 'Z': valueByKay = new FlyweightForZImpl(); break; } _initialized.Add(key, valueByKay); } return(valueByKay); }