Exemplo n.º 1
0
 public static void Main()
 {
     var popsicle = new Popsicle();
     popsicle.Value = 10;
     popsicle.Freeze();
     popsicle.Value = 20; // Bang!
 }
Exemplo n.º 2
0
    public static void Main()
    {
        var popsicle = new Popsicle();

        popsicle.Value = 10;
        popsicle.Freeze();
        popsicle.Value = 20; // Bang!
    }
Exemplo n.º 3
0
    public static void Main()
    {
        var popsicle = new Popsicle();

        popsicle.Value = 10;
        popsicle.Value = 15;
        popsicle.Freeze();
        Console.WriteLine(popsicle.Value); // 15? Memory model madness
        popsicle.Value = 20;               // Bang!
    }
Exemplo n.º 4
0
        public static void Run()
        {
            var popsicle = new Popsicle();

            popsicle.Value = 1;
            popsicle.Value = 2;
            popsicle.Freeze();
            //Exception!
            popsicle.Value = 2;
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            #region Level 0

            string name = " 123456 ";
            name.Trim();
            Console.WriteLine(name.Length);

            name = name.Trim(); // immutable always returns a new string
            Console.WriteLine(name.Length);

            #endregion

            #region Basic

            var r1 = new MutableRectangle();
            r1.Height = 10;
            r1.Length = 5;
            r1.Grow(10, 5);

            Console.WriteLine(r1.ToString());

            #endregion

            #region Patterns

            #region 1. Mutable
            var m = new Mutable();
            m.Value = 10;
            m.Value = 20;
            #endregion

            #region 2. ShallowMutable
            StringBuilder builder = new StringBuilder();
            builder.Append("foo");
            var sm = new ShallowMutable(10, builder);
            sm.Builder.Append("bar");
            Console.WriteLine(sm.Builder);
            #endregion

            #region 3. Popsicle
            var p = new Popsicle();
            p.Value = 10;
            p.Freeze();
            //p.Value = 20; //Bang!
            #endregion

            #region 4. ObservableImmutable

            #endregion

            #endregion

            Console.ReadLine();
        }