类间聚集关系理解(C#)

 


聚集说的是:一些对象由其他对象组成,阐述整体和部分之间的关系;

 

个人理解可以看成聊天室成员聚集共享:

 

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();
      }

       
       
        



        
        
    


 

 

 

 

 

 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值