Ejemplo n.º 1
0
        internal static void Main()
        {
            // Build a document with text
            const string Document = "AAZZBBZB";
            var chars = Document.ToCharArray();

            var factory = new CharacterFactory();

            // extrinsic state
            int pointSize = 10;

            // For each character use a flyweight object
            var list = new List<Character>();
            foreach (char c in chars)
            {
                pointSize++;
                var character = factory.GetCharacter(c);
                character.Display(pointSize);
                list.Add(character);
            }

            // Wait for user
            Console.ReadKey();
            Console.WriteLine();
            foreach (var c in list)
            {
                Console.WriteLine(c.PointSize);
            }
        }
Ejemplo n.º 2
0
        internal static void Main()
        {
            // Build a document with text
            const string Document = "AAZZBBZB";
            var chars = Document.ToCharArray();

            var factory = new CharacterFactory();

            // extrinsic state
            int pointSize = 10;

            // For each character use a flyweight object
            foreach (char c in chars)
            {
                pointSize++;
                var character = factory.GetCharacter(c);
                character.Display(pointSize);
            }

            // Ste se otpechata 3, tai kato e lazy inicialization i samo 3 vida bukvi(A,B,Z) imame v celia string AAZZBBZB
            Console.WriteLine(factory.Counter);

            // Wait for user
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        private void DisplaySimbols(string str)
        {
            var chars = str.ToCharArray();
            var f     = new CharacterFactory();

            foreach (var c in chars)
            {
                try
                {
                    var character = f.GetCharacter(c);
                    sp.Children.Add(new Image {
                        Source = character.Display()
                    });
                }
                catch {}
            }
        }
Ejemplo n.º 4
0
        static void Main()
        {
            string document = "AAZZBBZB";

            char[] chars = document.ToCharArray();

            CharacterFactory factory = new CharacterFactory();

            // For each character use a flyweight object
            foreach (char c in chars)
            {
                Character character = factory.GetCharacter(c);
                character.Display();
            }

            Console.ReadKey();
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            var document = "AA BB AB";
            var chars    = document.ToCharArray();
            var f        = new CharacterFactory();
            // position - this is external state
            var position = 0;

            // use for every symbol our flyweight-object (объект-приспособленец)
            foreach (var c in chars)
            {
                var character = f.GetCharacter(c);
                character.Display(position++);
            }

            Console.ReadLine();
        }
Ejemplo n.º 6
0
        private static CharacterFactory CreateCharacters()
        {
            var factory = new CharacterFactory();
            var choice  = YesOrNo[Asker.GetChoiceFromList("Are there any characters for which you want custom coloring?",
                                                          YesOrNo)];

            switch (choice)
            {
            case "No":
                return(factory);

            case "Yes":
                makeCustomCharacters();
                break;

            default:
                return(null);
            }

            return(factory);

            void makeCustomCharacters()
            {
                while (true)
                {
                    var character       = GetCharacter();
                    var foregroundColor = GetColor($"\nWhat do you want the foreground color of {character} to be?");
                    var backgroundColor = GetColor($"\nWhat do you want the background color of {character} to be?");

                    factory.SetCharacter(character, foregroundColor, backgroundColor);

                    var makeAnotherCharacter = YesOrNo[Asker.GetChoiceFromList("Are there any other characters for which you want custom coloring?",
                                                                               YesOrNo)];

                    switch (makeAnotherCharacter)
                    {
                    case "Yes":
                        continue;

                    default:
                        return;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        static void Main()
        {
            string document = "AAZZBBZB";

            char[] chars = document.ToCharArray();

            CharacterFactory f = new CharacterFactory();

            int pointSize = 10;

            foreach (char c in chars)
            {
                pointSize++;
                Character character = f.GetCharacter(c);
                character.Display(pointSize);
            }

            Console.Read();
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            string document = "AABBAB";

            char[] chars = document.ToCharArray();

            CharacterFactory characterFactory = new CharacterFactory();

            int pointSize = 10;

            foreach (char documentChars in chars)
            {
                pointSize++;
                Character character = characterFactory.GetCharacter(documentChars);
                character.Display(pointSize);
            }

            Console.ReadKey();
        }
Ejemplo n.º 9
0
        static void Main()
        {
            string document = "AAZZBBZB";

            char[] chars = document.ToCharArray();

            CharacterFactory factory = new CharacterFactory();

            // extrinsic state
            int pointSize = 10;

            // For each character use a flyweight object
            foreach (char c in chars)
            {
                pointSize++;
                Character character = factory.GetCharacter(c);
                character.Display(pointSize);
            }
        }
Ejemplo n.º 10
0
        public static void Main()
        {
            // Build a document with text
            string document = "ABBAABA";

            char[] chars = document.ToCharArray();

            var factory = new CharacterFactory();

            // Extrinsic state
            int pointSize = 10;

            // For each character use a flyweight object
            foreach (char c in chars)
            {
                pointSize++;
                Character character = factory.GetCharacter(c);
                character.Display(pointSize);
            }
        }
Ejemplo n.º 11
0
        private static void FlyweightDemo()
        {
            // Build a document with text
            const string Document = "AAZZBBZB";
            var          chars    = Document.ToCharArray();

            var factory = new CharacterFactory();

            // extrinsic state
            int pointSize = 10;

            // For each character use a flyweight object
            foreach (char c in chars)
            {
                pointSize++;
                var character = factory.GetCharacter(c);
                character.Display(pointSize);
            }

            Console.WriteLine("Number of objects: {0}", factory.NumberOfObjects);
        }
Ejemplo n.º 12
0
        private static void FlyweightDemo()
        {
            // Build a document with text
            const string Document = "AAZZBBZB";
            var chars = Document.ToCharArray();

            var factory = new CharacterFactory();

            // extrinsic state
            int pointSize = 10;

            // For each character use a flyweight object
            foreach (char c in chars)
            {
                pointSize++;
                var character = factory.GetCharacter(c);
                character.Display(pointSize);
            }

            Console.WriteLine("Number of objects: {0}", factory.NumberOfObjects);
        }
Ejemplo n.º 13
0
        internal static void Main()
        {
            // Build a document with text
            const string Document = "AAZZBBZB";
            var          chars    = Document.ToCharArray();

            var factory = new CharacterFactory();

            // extrinsic state
            int pointSize = 10;

            // For each character use a flyweight object
            foreach (char c in chars)
            {
                pointSize++;
                var character = factory.GetCharacter(c);
                character.Display(pointSize);
            }

            // Wait for user
            Console.ReadKey();
        }
Ejemplo n.º 14
0
        private static void FlyweightDemo()
        {
            // Build a document with text
            const string Document = "AAZZABBZZBAB";

            var characterFactory = new CharacterFactory();

            // extrinsic state
            var pointSize = 10;

            // For each character use a flyweight object
            foreach (var c in Document)
            {
                pointSize++;
                var character = characterFactory.GetCharacter(c);
                character.Display(pointSize);
            }

            Console.WriteLine(
                "Total number of character objects: {0}",
                characterFactory.NumberOfObjects);
        }
Ejemplo n.º 15
0
        internal static void Main()
        {
            // Build a document with text
            const string Document = "AAZZBBZB";
            var chars = Document.ToCharArray();

            var factory = new CharacterFactory();

            // extrinsic state
            var pointSize = 10;

            // For each character use a flyweight object
            foreach (var c in chars)
            {
                pointSize++;
                var character = factory.GetCharacter(c);
                character.Display(pointSize);
            }

            // Wait for user
            Console.ReadKey();
        }
Ejemplo n.º 16
0
    static void Main()
    {
      // Build a document with text
      string document = "AAZZBBZB";
      char[] chars = document.ToCharArray();

      CharacterFactory f = new CharacterFactory();

      // extrinsic state
      int pointSize = 10;

      // For each character use a flyweight object
      foreach (char c in chars)
      {
        pointSize++;
        Character character = f.GetCharacter(c);
        character.Display(pointSize);
      }

      // Wait for user
      Console.Read();
    }
Ejemplo n.º 17
0
        private static void FlyweightDemo()
        {
            // Build a document with text
            const string Document = "AAZZABBZZBAB";

            var characterFactory = new CharacterFactory();

            // extrinsic state
            var pointSize = 10;

            // For each character use a flyweight object
            foreach (var c in Document)
            {
                pointSize++;
                var character = characterFactory.GetCharacter(c);
                character.Display(pointSize);
            }

            Console.WriteLine(
                "Total number of character objects: {0}",
                characterFactory.NumberOfObjects);
        }
Ejemplo n.º 18
0
        static void Main()
        {
            // Build a document with text
            string document = "AAZZBBZB";

            char[] chars = document.ToCharArray();

            CharacterFactory f = new CharacterFactory();

            // extrinsic state
            int pointSize = 10;

            // For each character use a flyweight object
            foreach (char c in chars)
            {
                pointSize++;
                Character character = f.GetCharacter(c);
                character.Display(pointSize);
            }

            // Wait for user
            Console.Read();
        }