/// <summary> /// Entry point into console application. /// </summary> public void Run() { // Arbitrary extrinsic state int extrinsicstate = 22; var factory = new FlyweightFactory(); // Work with different flyweight instances var fx = factory.GetFlyweight("X"); fx.Operation(--extrinsicstate); var fy = factory.GetFlyweight("Y"); fy.Operation(--extrinsicstate); var fz = factory.GetFlyweight("Z"); fz.Operation(--extrinsicstate); var fu = new UnsharedConcreteFlyweight(); fu.Operation(--extrinsicstate); }
// "FlyweightFactory" // "ConcreteFlyweight" public void TestFlyWeigthPattern() { // Arbitrary extrinsic state int extrinsicstate = 22; var f = new FlyweightFactory(); // Work with different flyweight instances Flyweight fx = f.GetFlyweight("X"); fx.Operation(--extrinsicstate); Flyweight fy = f.GetFlyweight("Y"); fy.Operation(--extrinsicstate); Flyweight fz = f.GetFlyweight("Z"); fz.Operation(--extrinsicstate); var uf = new UnsharedConcreteFlyweight(); uf.Operation(--extrinsicstate); // Wait for user Console.Read(); }
static void Main(string[] args) { #region 字符串 外部 //string key1 = "科目1上海"; //string key2 = "科目1上海"; //FlyweightFactory.GetFlyweight(key1); //var sw = Stopwatch.StartNew(); //for (int i = 0; i < 1000000; i++) //{ // FlyweightFactory.GetFlyweight(key2); //} //Console.WriteLine("Time: {0}ms", sw.ElapsedMilliseconds); #endregion ExtrinsicState state1 = new ExtrinsicState(); state1.SetSubject("科目1"); state1.SetLocation("上海"); FlyweightFactory.GetFlyweight(state1); ExtrinsicState state2 = new ExtrinsicState(); state2.SetSubject("科目1"); state2.SetLocation("上海"); var sw = Stopwatch.StartNew(); for (int i = 0; i < 1000000; i++) { FlyweightFactory.GetFlyweight(state2); } Console.WriteLine("Time: {0}ms", sw.ElapsedMilliseconds); Console.ReadKey(); }
static void Main(string[] args) { FlyweightFactory flyweightFactory = new FlyweightFactory(); IFlyweight cafe = flyweightFactory.GetFlyweight("Expresso"); Console.WriteLine("*************Expresso****************"); Console.WriteLine("Tipo de Cafe = " + cafe.TipodeCafe()); Console.WriteLine("Tipo de Liquido = " + cafe.TipodeLiquido()); Console.WriteLine("Extras = " + cafe.Extras()); Console.WriteLine("Precio = " + cafe.Precio()); cafe = flyweightFactory.GetFlyweight("Caramelo Macchiato"); Console.WriteLine("**********Caramelo Macchiato*********"); Console.WriteLine("Tipo de Cafe = " + cafe.TipodeCafe()); Console.WriteLine("Tipo de Liquido = " + cafe.TipodeLiquido()); Console.WriteLine("Extras = " + cafe.Extras()); Console.WriteLine("Precio = " + cafe.Precio()); cafe = flyweightFactory.GetFlyweight("Capuchino con Canela"); Console.WriteLine("*********Capuchino con Canela********"); Console.WriteLine("Tipo de Cafe = " + cafe.TipodeCafe()); Console.WriteLine("Tipo de Liquido = " + cafe.TipodeLiquido()); Console.WriteLine("Extras = " + cafe.Extras()); Console.WriteLine("Precio = " + cafe.Precio()); cafe = flyweightFactory.GetFlyweight("Tea Verde"); Console.WriteLine("**************Tea Verde**************"); Console.WriteLine("Tipo de Cafe = " + cafe.TipodeCafe()); Console.WriteLine("Tipo de Liquido = " + cafe.TipodeLiquido()); Console.WriteLine("Extras = " + cafe.Extras()); Console.WriteLine("Precio = " + cafe.Precio()); Console.ReadKey(); }
/// <summary> /// Entry point into console application. /// </summary> static void Main() { // Arbitrary extrinsic state int extrinsicstate = 22; FlyweightFactory factory = new FlyweightFactory(); // Work with different flyweight instances Flyweight fx = factory.GetFlyweight("X"); fx.Operation(--extrinsicstate); Flyweight fy = factory.GetFlyweight("Y"); fy.Operation(--extrinsicstate); Flyweight fz = factory.GetFlyweight("Z"); fz.Operation(--extrinsicstate); UnsharedConcreteFlyweight fu = new UnsharedConcreteFlyweight(); fu.Operation(--extrinsicstate); // Wait for user Console.ReadKey(); }
public static void Main() { string extrinsicstate = "THIS IS A BIG EXTRINSIC STATE"; FlyweightFactory factory = new FlyweightFactory(); UnsharedConcreteFlyweight flyweights1 = new UnsharedConcreteFlyweight(new Flyweight[] { factory.GetFlyweight('a'), factory.GetFlyweight('a'), factory.GetFlyweight('b'), factory.GetFlyweight('c'), factory.GetFlyweight('a'), factory.GetFlyweight('c') }); UnsharedConcreteFlyweight flyweights2 = new UnsharedConcreteFlyweight(new Flyweight[] { factory.GetFlyweight('c'), factory.GetFlyweight('b'), factory.GetFlyweight('b'), factory.GetFlyweight('a'), factory.GetFlyweight('c'), factory.GetFlyweight('b') }); flyweights1.Operation(extrinsicstate); flyweights2.Operation(extrinsicstate); Console.ReadKey(); }
public void mem(int n) { //Flyweight atminties matavimas FlyweightFactory f = new FlyweightFactory(); State[] s = new State[n]; State[] s1 = new State[n]; GC.Collect(); GC.Collect(); GC.Collect(); long kbBefore = GC.GetTotalMemory(true); for (int i = 0; i < n; i++) { s[i] = f.GetFlyweight('W'); } long kbAfter1 = GC.GetTotalMemory(false); long kbAfter2 = GC.GetTotalMemory(true); System.Diagnostics.Debug.WriteLine("Flyweight: memory usage with flyweight: n = {0}, {1}", n, kbAfter2 - kbBefore); GC.Collect(); GC.Collect(); GC.Collect(); kbBefore = GC.GetTotalMemory(true); for (int i = 0; i < n; i++) { s1[i] = new Waiting(); } kbAfter1 = GC.GetTotalMemory(false); kbAfter2 = GC.GetTotalMemory(true); System.Diagnostics.Debug.WriteLine("Flyweight: memory usage without flyweight: n = {0}, {1}", n, kbAfter2 - kbBefore); }
void TestFlyWeight() { FlyweightFactory factory = new FlyweightFactory(); FlyWeight flyWeightX = factory.GetFlyweight("酷炫效果"); flyWeightX.Operation(); FlyWeight flyWeightY = factory.GetFlyweight("旋转效果"); flyWeightY.Operation(); FlyWeight flyWeightZ = factory.GetFlyweight("光影效果"); flyWeightZ.Operation(); FlyWeight flyWeightUnshared = new UnsharedConcreteFlyWeight("火焰效果"); flyWeightUnshared.Operation(); FlyWeight flyWeightM = factory.GetFlyweight("光影效果"); flyWeightM.Operation(); FlyWeight flyWeightN = factory.GetFlyweight("光影效果"); flyWeightN.Operation(); Debug.Log("Total number of fly weight : " + factory.GetFlyWeightCount()); }
//Пристосуванець - Flyweight public Run Flyweight() { Console.WriteLine("\nFlyweight:"); // Arbitrary extrinsic state int extrinsicstate = 22; FlyweightFactory factory = new FlyweightFactory(); // Work with different flyweight instances Patterns.Structural.Flyweight.Flyweight fx = factory.GetFlyweight("X"); fx.Operation(--extrinsicstate); Patterns.Structural.Flyweight.Flyweight fy = factory.GetFlyweight("Y"); fy.Operation(--extrinsicstate); Patterns.Structural.Flyweight.Flyweight fz = factory.GetFlyweight("Z"); fz.Operation(--extrinsicstate); UnsharedConcreteFlyweight fu = new UnsharedConcreteFlyweight(); fu.Operation(--extrinsicstate); return(this); }
public static void FlyweightStructural() { // Arbitrary extrinsic state int extrinsicstate = 22; FlyweightFactory factory = new FlyweightFactory(); // Work with different flyweight instances Flyweight fx = factory.GetFlyweight("X"); fx.Operation(--extrinsicstate); Flyweight fy = factory.GetFlyweight("Y"); fy.Operation(--extrinsicstate); Flyweight fz = factory.GetFlyweight("Z"); fz.Operation(--extrinsicstate); UnsharedConcreteFlyweight fu = new UnsharedConcreteFlyweight(); fu.Operation(--extrinsicstate); }
public void TestFlyweight() { var flyweightFactory = new FlyweightFactory(); var unsharedFlyWeightOne = new UnsharedFlyweight(flyweightFactory.GetObject("FlyWeightOne")); var unsharedFlyWeightTwo = new UnsharedFlyweight(flyweightFactory.GetObject("FlyWeightOne")); Assert.AreEqual(unsharedFlyWeightOne.GetState(), unsharedFlyWeightTwo.GetState()); }
public void Show() { var factory = new FlyweightFactory(); var conc1 = factory.GetFlyweight("conc1"); var conc2 = factory.GetFlyweight("conc1"); conc1.Operation("1"); conc2.Operation("2"); }
public void RestoreState() { //Flyweight naudojimas: FlyweightFactory ff = new FlyweightFactory(); this.State2 = new ContextState(ff.GetFlyweight('W')); System.Diagnostics.Debug.WriteLine("Flyweight: Waiting"); //State naudojimas be flyweight: this.State2 = new ContextState(new Waiting()); }
public CosmeticMenu() { FactoryProvider prov = new FactoryProvider(); cosRepos = prov.GetFactory().GetCosmeticRepository(); cart = prov.GetFactory().GetCartRepository(); //cart. //cart = new CartFileRepository(); factory = new FlyweightFactory(); }
public void FlyweightPatternCodeTest() { FlyweightFactory factory = new FlyweightFactory(); var flyweightA1 = factory.GetFlyweight("A"); flyweightA1.Operation(); var flyweightA2 = factory.GetFlyweight("A"); }
public Client() { FlyweightFactory flyweightFactory = new FlyweightFactory(); for (int i = 0; i < 100; i++) { IComponent component = flyweightFactory.ObtainComponent("ConcreateComponentA"); component.Operation(); } }
string AddCarToPoliceDatabase(FlyweightFactory factory, Car car) { var flyweight = factory.GetFlyweight(new Car { Color = car.Color, Model = car.Model, Company = car.Company }); return(flyweight.Operation(car)); }
public void FlyweightTest() { var factory = new FlyweightFactory(); var m = factory.GetFlyweight("A"); m.Operation(1); var d = factory.GetFlyweight("A"); Console.WriteLine(d.GetState()); }
void ItSets_StateStarted_WhenGameStarted() { var flyweights = new FlyweightFactory(); var game = Game.Instance; var state = flyweights.GetState(GameStates.Started); state.DoAction(game); Assert.IsType <GameStartedState>(game.GetState()); }
public MedicineMenu() { FactoryProvider prov = new FactoryProvider(); medRepos = prov.GetFactory().GetMedicineRepository(); cart = prov.GetFactory().GetCartRepository(); //cart = new CartFileRepository(); factory = new FlyweightFactory(); }
static void Main() { var factory = new FlyweightFactory(); var flyweight1 = factory.GetFlyweight("A"); var flyweight2 = factory.GetFlyweight("A"); var flyweight3 = factory.GetFlyweight("B"); flyweight1.Display(); flyweight2.Display(); flyweight3.Display(); }
public AppFormUser() { factory = new FlyweightFactory(); prov = new FactoryProvider(); medRepos = prov.GetFactory().GetMedicineRepository(); cosRepos = prov.GetFactory().GetCosmeticRepository(); cartRepos = prov.GetFactory().GetCartRepository(); InitializeComponent(); // Load_Med_Columns(); Load_Cos_Columns(); }
public void ItBuilds_StartedFlyweight() { var flyweightFactory = new FlyweightFactory(); var startedFlyweight = flyweightFactory.GetState(GameStates.Started); var startedFlyweight2 = flyweightFactory.GetState(GameStates.Started); Assert.NotNull(startedFlyweight); Assert.NotNull(startedFlyweight2); Assert.Equal(startedFlyweight, startedFlyweight2); }
public void ItBuilds_Flyweight() { var flyweightFactory = new FlyweightFactory(); var flyweight = flyweightFactory.GetState(GameStates.Ended); var flyweight2 = flyweightFactory.GetState(GameStates.Ended); Assert.NotNull(flyweight); Assert.NotNull(flyweight2); Assert.Equal(flyweight, flyweight2); }
static void Main(string[] args) { FlyweightFactory factory = new FlyweightFactory(); FlyweightContext charAFirstContext = new FlyweightContext(5, 5, "red"); factory.GetFlyweight("charA").Draw(charAFirstContext); FlyweightContext charASndContext = new FlyweightContext(1, 3, "green"); factory.GetFlyweight("charA").Draw(charASndContext); }
static void Main() { int extrinsicstate = 22; FlyweightFactory f = new FlyweightFactory(); Flyweight fx = f.GetFlyweight("X"); fx.Operation(--extrinsicstate); Flyweight uf = new UnshareConcreteFlyweight(); uf.Operation(--extrinsicstate); Console.ReadKey(); }
// Use this for initialization void Start() { FlyweightFactory flyFactory = new FlyweightFactory(); Flyweight flyweight = flyFactory.GetFlyweight("A"); Debug.Log(flyweight.GetData()); Flyweight flyweight2 = flyFactory.GetFlyweight("A"); // 같은데이터 값은 재사용 한다. Debug.Log(flyweight2.GetData()); Flyweight flyweight3 = flyFactory.GetFlyweight("CC"); // 새로운 것만 생성 Debug.Log(flyweight3.GetData()); }
private static void AddCarToPoliceDatabase(FlyweightFactory factory, Car car) { var flyweight = factory.GetFlyweight(new Car { Color = car.Color, Model = car.Model, Company = car.Company }); // The client code either stores or calculates extrinsic state and // passes it to the flyweight's methods. flyweight.Operation(car); }
static void Main(string[] args) { int state = 0; FlyweightFactory factory = new FlyweightFactory(); Flyweight flyweight = factory.GetFlyweight("2"); flyweight.Operation(state); flyweight = factory.GetFlyweight("228"); flyweight.Operation(state); flyweight = new UnsharedFlyweight(); flyweight.Operation(state); }
public User() { Losses = 0; Wins = 0; Picture = (1 + random.Next(22)) + ".png"; State = new MementoClient(); //Flyweight naudojimas: FlyweightFactory ff = new FlyweightFactory(); State2 = new ContextState(ff.GetFlyweight('W')); System.Diagnostics.Debug.WriteLine("Flyweight: Waiting"); //State naudojimas be flyweight: State2 = new ContextState(new Waiting()); }
public static void Main( string[] args ) { // Arbitrary extrisic state int extrinsicstate = 22; FlyweightFactory f = new FlyweightFactory(); // Work with different flyweight instances Flyweight fx = f.GetFlyweight("X"); fx.Operation( --extrinsicstate ); Flyweight fy = f.GetFlyweight("Y"); fy.Operation( --extrinsicstate ); Flyweight fz = f.GetFlyweight("Z"); fz.Operation( --extrinsicstate ); UnsharedConcreteFlyweight fu = new UnsharedConcreteFlyweight(); fu.Operation( --extrinsicstate ); }
// Entry point into console application. static void Main() { // Arbitrary extrinsic state int extrinsic_state = 22; factory = new FlyweightFactory(); // Work with different flyweight instances ch = factory.GetFlyweight("X"); ch.Operation(--extrinsic_state); ch = factory.GetFlyweight("Y"); ch.Operation(--extrinsic_state); ch = factory.GetFlyweight("Z"); ch.Operation(--extrinsic_state); ch = new UnsharedConcreteFlyweight(); ch.Operation(--extrinsic_state); // Wait for user Console.ReadKey(); }
public static void Test() { var factory = new FlyweightFactory(); var ConcreteFlyweight1 = factory[1]; var ConcreteFlyweight2 = factory[2]; }