类间聚集关系理解
2011-12-08 18:15
225 查看
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)
{
//类的依赖关系 ,类Person调用类Air的方法ReleasePower();
/* Person me=new Person ();
while (true)
{
me.breath();
}*///
//类的聚集关系--人都需要呼吸,人作为结点加入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();
}
/// <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)
{
//类的依赖关系 ,类Person调用类Air的方法ReleasePower();
/* Person me=new Person ();
while (true)
{
me.breath();
}*///
//类的聚集关系--人都需要呼吸,人作为结点加入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();
}
相关文章推荐
- 类间聚集关系理解(C#)
- 深入理解子元素的width与父元素的width关系
- 如何理解Nginx, WSGI, Flask之间的关系
- 深入理解 Laravel Eloquent(三)——模型间关系(关联)
- React Native与原生关系理解与对比
- Android 异步消息处理机制 让你深入理解 Looper、Handler、Message三者关系
- 如何更好的理解控件的层次关系
- Android 异步消息处理机制 让你深入理解 Looper、Handler、Message三者关系
- CSS深入理解vertical-align和line-height的基友关系
- 深入理解 c# 第五章 不同种类的变量和匿名方法的关系
- 如何理解session和cookie的关系(例子那是相当的好理解),附带session共享
- 关系代数中的除法--概念的理解
- 初步理解数据库锁和事务的关系
- 【话题讨论功能模块】话题讨论类关系【用于理解一对多等映射、级联关系】
- 关于域名解析即DNS的理解,以及hosts文件跟域名解析的关系。tomcat发布的工程,怎么设置一个虚拟域名?
- 深入理解 C++ 指针(七)---指针和函数的关系
- 如何理解session和cookie的关系(例子那是相当的好理解),附带session共享
- putchar和printf的区别,以及数组和指针的关系理解
- 我理解c#(一): 参数传递和变量复制之间的关系
- 线程进程Java多线程(一)、理解进程与多线程的概念及关系