static void Main(string[] args)
        {
            ConcreteCloneable concrete = new ConcreteCloneable();

            concrete.Id   = 1;
            concrete.Name = "Un nombre";

            ConcreteCloneable cloned = concrete.ShallowCopy() as ConcreteCloneable;

            if (cloned != null)
            {
                cloned.Id   = 3;
                cloned.Name = "Cambiado";
            }

            IObjectPool pool = ObjectPool.GetInstance();

            Parallel.For(0, 1000000, (i) =>
            {
                IPooledObject reusable = pool.GetConnection();

                reusable.DoSomething();

                reusable.Release();
            });
        }
Exemple #2
0
    protected override HandleCloned(AbstractCloneable clone)
    {
        //Clone is of the current type.
        ConcreteCloneable obj = (ConcreteCloneable)clone;

        //Here you have a superficial copy of "this". You can do wathever
        //specific task you need to do.
        //e.g.:
        obj.SomeReferencedPropertie = this.SomeReferencedPropertie.Clone();
    }
    protected override HandleCloned(AbstractCloneable clone)
    {
        //Get whathever magic a base class could have implemented.
        base.HandleCloned(clone);
        //Clone is of the current type.
        ConcreteCloneable obj = (ConcreteCloneable)clone;

        //Here you have a superficial copy of "this". You can do whathever
        //specific task you need to do.
        //e.g.:
        obj.SomeReferencedProperty = this.SomeReferencedProperty.Clone();
    }
 public ConcreteCloneable(ConcreteCloneable d)
     : base(d)
 {
     DerivedValue = d.DerivedValue;
 }