using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication104
{
public class MobileStorageEquipment
{
public void connect()
{
Console.WriteLine("The equipment can connect with the computer");
}
}
public interface IEquipmentInterface
{
void read();
void write();
}
//now there is a new equipment which contains the method :newread() and newwrite()
//it must introduce a adapter
public interface Inewfunction
{
void newread();
void newwrite();
}
//the adapter
public class oneadapter
{
private Inewfunction _newUSBDriver;
public Inewfunction newUSBDriver
{
get
{
return this._newUSBDriver;
}
set
{
this._newUSBDriver = value;
}
}
public oneadapter()
{
}
public oneadapter(Inewfunction newusbdriver)
{
this._newUSBDriver = newusbdriver ;
}
public void newreaddate()
{
this._newUSBDriver.newread();
}
public void newwritedata()
{
this._newUSBDriver.newwrite();
}
}
//mp3player
public class mp3player : MobileStorageEquipment,IEquipmentInterface
{
public void read()
{
Console.WriteLine("reading from the computer");
Console.WriteLine("reading finished");
}
public void write()
{
Console.WriteLine("writing to the mp3player");
Console.WriteLine("writing finished");
}
}
//flashdisk
public class flashdisk : MobileStorageEquipment,IEquipmentInterface
{
public void read()
{
Console.WriteLine("reading from the computer");
Console.WriteLine("reading finished");
}
public void write()
{
Console.WriteLine("writing to the flashdisk");
Console.WriteLine("writing finished");
}
}
//Mobileharddisk
public class Mobileharddisk : MobileStorageEquipment,IEquipmentInterface
{
public void read()
{
Console.WriteLine("reading from the computer");
Console.WriteLine("reading finished");
}
public void write()
{
Console.WriteLine("writing to the Mobileharddisk");
Console.WriteLine("writing finished");
}
}
//the new equipment
public class newequipment : MobileStorageEquipment,Inewfunction
{
public void newread()
{
Console.WriteLine("the new equipment : reading from the computer ");
}
public void newwrite()
{
Console.WriteLine("the new equipment : writing to the new equioment");
}
}
public class computer
{
private IEquipmentInterface _USBDriver;
public IEquipmentInterface USBDriver
{
get
{
return this._USBDriver;
}
set
{
this._USBDriver = value;
}
}
public computer()
{
}
public computer(IEquipmentInterface usbdriver)
{
this.USBDriver = usbdriver;
}
public void readdata()
{
this._USBDriver.read();
}
public void writedata()
{
this._USBDriver.write();
}
}
class Program
{
static void Main(string[] args)
{
computer mycomputer = new computer();
mp3player mymp3player = new mp3player();
mycomputer.USBDriver = mymp3player;
Console.WriteLine("test the mp3player");
mymp3player.connect();
Console.WriteLine();
Console.WriteLine("now insert the mp3player into the computer to copy some music from it\n");
mycomputer.writedata();
Console.WriteLine();
Console.WriteLine("now insert the mp3player into the computer\ncopy some files to the computer\n");
mycomputer.readdata();
Console.WriteLine();
Console.WriteLine("now test the new equipment\n");
newequipment mynewequipment = new newequipment();
oneadapter myadapter = new oneadapter();
myadapter.newUSBDriver = mynewequipment;
myadapter.newreaddate();
myadapter.newwritedata();
}
}
}