public static void Adapter()
 {
     IAdapter adapter = new Adapter();
     Console.WriteLine(adapter.Sum(10, 2));
     Adaptee adaptee = new Adaptee();
     Console.WriteLine(adaptee.OldSum(10.00, 10.00));
 }
    static void Main(string[] args)
    {
        Console.WriteLine("Adaptor Pattern \n");

        Adaptee precise = new Adaptee();
        Console.WriteLine("Before the standard precise reading: ");
        Console.WriteLine(precise.SpecificRequest(5, 3));

        ITarget adoptedObj = new Adoptor();
        Console.WriteLine("Standard precise reading: ");
        Console.WriteLine(adoptedObj.Request(5, 3));
        Console.ReadLine();

        /*
         * Output:
         *
         * Adaptor Pattern
         *
         * Before the standard precise reading:
         * 1.66666666666667
         * Standard precise reading:
         * Rough estimate is 2
         *
         */
    }
 // Different constructs for the expected target/adaptees
 // Construct 1: Adapter-Adaptee
 public Adapter(Adaptee adaptee)
 {
     // Set the delegate to the new standard
     Request = delegate(int a, int b)
     {
         return "(Precised) Estimate is " + (int)Math.Round(Precise((double)a, (double)b));
     };
 }
    public void Main()
    {
        // Showing the Adapteee in standalone mode
        var first = new Adaptee();
        Console.Write("Before the new standard\nPrecise reading: ");
        Console.WriteLine(first.SpecificRequest(5, 3));

        // What the client really wants
        ITarget second = new Adapter();
        Console.WriteLine("\nMoving to the new standard");
        Console.WriteLine(second.Request(5));
    }
        protected override PropertyDescriptorCollection GenerateDescriptors()
        {
            var result = new List <System.ComponentModel.PropertyDescriptor>();

            foreach (var adapter in Adaptee.AsAll <object>())
            {
                Type adapterType = adapter.GetType();
                BindingAdapterPropertyDescriptor[] descriptors = GetDescriptorsFromBaseTypes(adapterType);
                MergeDescriptors(result, descriptors);
            }

            return(new PropertyDescriptorCollection(result.ToArray()));
        }
        public void Adapter_Test()
        {
            var adaptee = new Adaptee()
            {
                state = true
            };

            var client = new Client(new Adapter(adaptee));

            var result = client.GetValue();

            Assert.AreEqual(adaptee.state.ToString(), result);
        }
Exemple #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("START RUNNING ADAPTER.");
            Adaptee adaptee = new Adaptee();
            ITarget target  = new Adapter(adaptee);

            Console.WriteLine("Adaptee interface is incompatible with the client.");
            Console.WriteLine("But with adapter client can call it's method.");

            Console.WriteLine(target.GetRequest());
            Console.WriteLine("END RUNNING ADAPTER.");
            Console.ReadKey();
        }
Exemple #8
0
    static void  MainRun()
    {
        // Showing the Adapteee in stand-alone mode
        Adaptee first = new Adaptee();

        Console.Write("Before the new standard\nPrecise reading: ");
        Console.WriteLine(first.SpecificRequest(5, 3));

        // What the client really wants
        ITarget second = new Adapter();

        Console.WriteLine("\nMoving to the new standard");
        Console.WriteLine(second.Request(5));
    }
Exemple #9
0
 public void Log(string content, bool push = false)
 {
     try
     {
         Adaptee.Log(content, push);
     }
     catch (Exception e)
     {
         if (ErrorHandler != null)
         {
             ErrorHandler.Invoke(this, e);
         }
     }
 }
Exemple #10
0
            public static void Start()
            {
                // Showing the Adapteee in standalone mode
                Adaptee first = new Adaptee();

                Console.WriteLine("Before new standard pricing");
                Console.WriteLine(first.SpecialRequest(8, 3));


                // What the client really wants
                ITarget second = new Adapter();

                Console.WriteLine("\nMoving to the new standard");
                Console.WriteLine(second.Request(8));
            }
Exemple #11
0
        public void OperatorAdaptee()
        {
            Adaptee adaptee = new Adaptee();

            adaptee.Code = 2;

            Target target = adaptee;

            Assert.AreEqual <int>(adaptee.Code, target.Data);
            List <Target> targets = new List <Target>();

            targets.Add(adaptee);
            targets.Add(adaptee);

            var n = targets[1].Data;
        }
        public PluggableAdapter(Adaptee adaptee)
        {
            switch (adaptee)
            {
            case Adaptee.A:
            {
                request = new AdapteeA().SpecificRequestA;
            }
            break;

            case Adaptee.B:
            {
                request = new AdapteeB().SpecificRequestB;
            }
            break;
            }
        }
Exemple #13
0
        public bool Remove(E e)
        {
            int index = Adaptee.IndexOf(e);

            if (index < 0)
            {
                return(false);
            }
            Adaptee.RemoveAt(index);
            CollectionChanged?.Invoke(
                this,
                new NotifyCollectionChangedEventArgs(
                    NotifyCollectionChangedAction.Remove,
                    e,
                    index
                    )
                );
            return(true);
        }
Exemple #14
0
        public void SimpleTest()
        {
            bool pass = true;

            try
            {
                Adaptee adaptee = new Adaptee();
                ITarget target  = new Adapter(adaptee);

                //"Adaptee interface is incompatible with the client."
                //"But with adapter client can call it's method."

                target.GetRequest();
                //Console.WriteLine(target.GetRequest());
            }
            catch
            {
                pass = false;
            }

            Assert.True(pass);
        }
Exemple #15
0
 public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
 {
     return(Convert((ITimeSpaceValueSet)Adaptee.GetValues(querySpecifier)));
 }
Exemple #16
0
 public Adapter()
 {
     adaptee = new Adaptee();
 }
Exemple #17
0
 public IEnumerator GetEnumerator()
 {
     return(Adaptee.GetEnumerator());
 }
Exemple #18
0
 public int IndexOf(E e)
 {
     return(Adaptee.IndexOf(e));
 }
Exemple #19
0
 public SomeAdapter()
 {
     _adaptee = new Adaptee();
 }
Exemple #20
0
 public MovieAdapter(Adaptee adaptee)
 {
     this.adaptee = adaptee;
 }
 public ReferenceAdapter(Adaptee adaptee)
 {
     _adaptee = adaptee;
 }
Exemple #22
0
 public DomainObjectAdapter(Adaptee adaptee)
 {
     this.adaptee = adaptee;
 }
Exemple #23
0
        protected bool CanCollide(Body thisBody, Body otherBody /*, Physics2DDotNet.Ignorers.Ignorer otherIgnorer*/)
        {
            var other = (PhysicsBody)(otherBody.Tag);

            return(Adaptee.CanCollide((IPhysicsBody)thisBody.Tag, other, other.CollisionIgnorer));
        }
Exemple #24
0
 public Adapter()
 {
     this.adaptee = new Adaptee();
 }
Exemple #25
0
 public Adapter()
 {
     _adaptee = new Adaptee();
 }
 public Adapter_Wrapper(Adaptee adaptee)
 {
     this.adaptee = adaptee;
 }
 public Adapter(Adaptee adaptee) => this.adaptee = adaptee;
Exemple #28
0
 public CompositeAdapter()
 {
     _adaptee = new Adaptee();
 }
Exemple #29
0
 public void Request()
 {
     adaptee = new Adaptee();
     adaptee.SpecificRequest();
 }
Exemple #30
0
		public Adapter(Adaptee adaptee) {
			this._adaptee = adaptee;
		}
 public Adapter(Adaptee adaptee)
 {
     this._adaptee = adaptee;
 }
Exemple #32
0
 public Adapter(Adaptee adaptee)
 => _adaptee = adaptee;
Exemple #33
0
 public Adapter(Adaptee adaptee)
 {
     _adaptee = adaptee;
 }
 internal void EndContext(PageExecutionContextAdapter context)
 {
     Adaptee.EndContext(context.Adaptee);
 }
Exemple #35
0
        /// <summary>
        /// Client
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            #region Adapter

            Console.WriteLine("Adapter initialize ");

            Target target  = new Target();
            Target target2 = new Adaptee();

            Target target3 = new Adapter.Adapter();
            target.Request();
            Console.ReadKey();

            Console.WriteLine("Adapter Finalize " + Environment.NewLine);

            #endregion

            #region Bridge

            Console.WriteLine("Bridge initialize ");

            //Step 1
            ExportationBridge exp = new ExportationDOC();
            exp.Export();

            //Apply Brige Pattern
            Exportation exportacao = new ExportationEx();

            //Inject object
            exportacao.Implementor = new ExportationPDF();
            exportacao.Export();

            Console.WriteLine("Bridge finalize" + Environment.NewLine);
            Console.ReadKey();

            #endregion

            #region Composite

            Console.WriteLine("Composite initialize");

            var form = new Form("Cadastro Clientes");
            form.Add(new Button("Incluir"));
            form.Add(new Button("Consultar"));
            form.Add(new TextBox("Nome"));
            form.Add(new TextBox("Fone"));
            form.Display();

            Console.WriteLine("Composite finalize" + Environment.NewLine);
            Console.ReadKey();

            #endregion

            #region Decorator

            Console.WriteLine("Decorator initialize");

            //Step 1
            var dec = new DataSet();
            dec.Write();

            //Apply Decorator
            DataSet c = new DataSet();
            DataSetConcreteDecorator d = new DataSetConcreteDecorator();

            //Setando objeto a ser decorado
            d.setDatasetbase(c);
            d.Write();
            d.WriteXML();

            Console.WriteLine("Decorator finalize" + Environment.NewLine);
            Console.ReadKey();

            #endregion

            #region Facade

            Console.WriteLine("Facade initialize");

            //Step 1
            var email = new Mail(new SMTPSettings());
            var msg   = new MailMessage(new MailFormatTXT());
            msg.Message = "Hello world";
            email.Send(msg);
            Console.ReadKey();

            //Apply Facade pattern
            var emailFachada = new Email();
            emailFachada.Send("Hello world");

            Console.WriteLine("Facade finalize");
            Console.ReadKey();

            #endregion

            #region Flyweight

            Console.WriteLine("Flyweight initialize");

            int ext = 10;

            FlyweightFactory  factory = new FlyweightFactory();
            FlyweightAbstract f1      = factory.GetFlyweight("A");
            f1.Operation(ext++);
            FlyweightAbstract f2 = factory.GetFlyweight("B");
            f2.Operation(ext++);
            FlyweightAbstract f3 = factory.GetFlyweight("C");
            f3.Operation(ext++);
            FlyweightAbstract f4 = new UnsharedConcreteFlyweight();
            f4.Operation(ext++);

            Console.WriteLine("Flyweight finalize" + Environment.NewLine);
            Console.ReadKey();

            #endregion

            #region Proxy

            Console.WriteLine("Proxy initialize");

            //Step 1
            var calc = new Calc();
            var r    = calc.Somar(3, 5);
            Console.WriteLine(r.ToString());
            Console.ReadLine();

            //Aplly Proxy Pattern
            var calcProxy = new CalcProxy();
            var r2        = calcProxy.Somar(3, 5);
            Console.WriteLine(r2.ToString());

            Console.WriteLine("Proxy finalize" + Environment.NewLine);
            Console.ReadLine();

            #endregion
        }
 internal void BeginContext(PageExecutionContextAdapter context)
 {
     Adaptee.BeginContext(context.Adaptee);
 }