110,534
社区成员
发帖
与我相关
我的任务
分享
public class PersonalComputer
{
private string _cpuName;
private string _memoryName;
public PersonalComputer(string cpuName,string memoryName)
{
_cpuName = cpuName;
_memoryName = memoryName;
}
public string GetPCInfo()
{
return "CPU:"+_cpu+ "\r\n内存:"+_memory;
}
}
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
PersonalComputer pc1 = new PersonalComputer ('InterCPU','HynixMemory');
MessageBox.Show(pc1.GetPCInfo());
PersonalComputer pc2 = new PersonalComputer('AmdCPU','KingMaxMemory');
MessageBox.Show(pc2.GetPCInfo());
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace StrategyExample1
{
public interface ICPU
{
string Insert();
}
}
namespace StrategyExample1
{
public interface IMemory
{
string Insert();
}
}
namespace StrategyExample1
{
public class IntelCPU:ICPU
{
public string Insert()
{
return "IntelCPU";
}
}
}
namespace StrategyExample1
{
public class AMDCPU:ICPU
{
public string Insert()
{
return "AMDCPU";
}
}
}
namespace StrategyExample1
{
public class HynixMemory:IMemory
{
public string Insert()
{
return "现代内存";
}
}
}
namespace StrategyExample1
{
class KingStonMemory:IMemory
{
public string Insert()
{
return "金士顿内存";
}
}
}
namespace StrategyExample1
{
public class PersonalComputer
{
private ICPU _cpu;
private IMemory _memory;
public void InsertCPU(ICPU cpu)
{
_cpu = cpu;
}
public void InsertMemory(IMemory memory)
{
_memory = memory;
}
public string GetPCInfo()
{
return "CPU:"+_cpu.Insert() + "\r\n内存:"+_memory.Insert();
}
}
}
namespace StrategyExample1
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
PersonalComputer pc1 = new PersonalComputer();
pc1.InsertCPU(new IntelCPU());
pc1.InsertMemory(new HynixMemory());
MessageBox.Show(pc1.GetPCInfo());
PersonalComputer pc2 = new PersonalComputer();
pc2.InsertCPU(new AMDCPU());
pc2.InsertMemory(new KingStonMemory());
MessageBox.Show(pc2.GetPCInfo());
}
}
}