聚集说的是:一些对象由其他对象组成,阐述整体和部分之间的关系;
个人理解可以看成聊天室成员聚集共享:
C# Code:
/// <summary>
///
/// </summary>
/// 这类似聊天室的聚集
class Human
{
private string name;
private Breath BreathState,DeathY;
public Human(string Name,Breath Air,Breath deathY)
{
name = Name;
BreathState = Air;
DeathY = deathY;
}
public override string ToString()
{
string result;
result = name + "\n";
result += "BreathState:" + BreathState + "\n";
result += "DeathState:" + DeathY + "\n";
return result;
}
}
class Breath
{
//类似聊天室里的文件共享功能模块!
private string breathState;//呼吸状况
private string deathState;
public Breath(string state,string State)
{
breathState = state;
deathState = State;
}
public override string ToString()
{
string result;
result = breathState + "\n";
result += deathState + "\n";
return result;
}
}
static void Main(string[] args)
{
//类的聚集关系--人都需要呼吸,人作为结点加入Human这个聚集,Human对象是可以被加入到 对象共享的;
Breath Sbreath=new Breath ("呼吸正常!","还没死!");
Breath Sdeath=new Breath ("活着!","很好!");
Human S = new Human("Steven", Sbreath, Sdeath);
Breath Wbreath = new Breath("呼吸困难!", "快死了");
Breath Wdeath = new Breath("死了!", "哭吧!");
Human W = new Human("WiFi", Wbreath, Wdeath);
Console.WriteLine(S);
Console.WriteLine();
Console.WriteLine(W);
Console.ReadKey();
}