creativity in code.

creativity is that spark of electricity before an explosion.
it allows us, in a single instance to explore all possibilities without hesitation.

Programming - Adapter Structural Design Pattern


Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

The classes and/or objects participating in this example are:


  • Targetand
    • defines the domain-specific interface that Client uses.
  • Adapterand
    and and
    • adapts the interface Adaptee to the Target interface.
  • Adapteeand
    and and
    • defines an existing interface that needs adapting.
  • Clientand
    and and
    • collaborates with objects conforming to the Target interface.
using
System;

namespace DoFactory.GangOfFour.Adapter.Structural
{

// Mainapp test application

class MainApp
{
static void Main()
{
// Create adapter and place a request
Target target = new Adapter();
target.Request();

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

// "Target"

class Target
{
public virtual void Request()
{
Console.WriteLine("Called Target Request()");
}
}

// "Adapter"

class Adapter : Target
{
private Adaptee adaptee = new Adaptee();

public override void Request()
{
// Possibly do some other work
// and then call SpecificRequest
adaptee.SpecificRequest();
}
}

// "Adaptee"

class Adaptee
{
public void SpecificRequest()
{
Console.WriteLine("Called SpecificRequest()");
}
}
}

Output expected:


Called SpecificRequest()



Other pages of interest:
[+] Programming - VB.NET converting an Image to a Base64 string and back again
[+] .NET - Convert .lit files to XML and HTML - LitConvertor.NET
[+] Embedded Systems Engineering Embedded software and embedded systems, are those that require 100% o..
[+] Enterprise Java performance tuning tips
[+] Microsoft Announces New Support for Silverlight by Content Companies Worldwide
[+] WebLogic man goes full circle with SpringSource
[+] NET application server fundamentals for the enterprise
[+] Where will AJAX be in the future and is vanilla AJAX dead
[+] The Eclipse Project has released Eclipse 3.4 Ganymede
[+] Object Oriented Programming
[+] DAL and the nHibernate Question
[+] Running C and Python in browser. Advent of the Low Level Virtual Machine
[+] Database design
[+] Web Design and Web Development


Comments(2)

Posted by Hello! cialis , on 11/5/2009 5:43:16 PM
Hello! cialis ,

Posted by fnuoufyaw on 12/13/2009 6:41:13 AM


add comment Add Comment

Add your comment

Email address:
Your name:
Do you want your email to be visible?: