⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 employee.cs

📁 c#设计模式随书源码 c#设计模式随书源码
💻 CS
字号:
using System;
using System.Collections ;
namespace Composite
{
	/// <summary>
	/// Summary description for Employee.
	/// </summary>
	public class Employee :AbstractEmployee 	{
		protected float salary;
		protected string name;
		protected ArrayList subordinates;
		//------
		public Employee(string nm, float salry) 		{
			subordinates = new ArrayList();
			name = nm;
			salary = salry;
		}
		//------
		public float getSalary() {
			return salary;
		}
		//------
		public string getName() {
			return name;
		}
		//------
		public bool isLeaf() {
			return subordinates.Count == 0;
		}
		//------
		public virtual void add(string nm, float salary) {
			  throw new Exception("No subordinates in base employee class");
		}
		//------
		public virtual void add(AbstractEmployee emp) {
			throw new Exception("No subordinates in base employee class");
		}
		//------
		public IEnumerator getSubordinates() {
			return subordinates.GetEnumerator ();
		}
		public virtual AbstractEmployee getChild() {
			return null;
		}
		//------		
		public float getSalaries() {
			float sum;
			AbstractEmployee esub;
			//get the salaries of the boss and subordinates
			sum = getSalary();
			IEnumerator enumSub = subordinates.GetEnumerator() ;
			while (enumSub.MoveNext())  {
				esub = (AbstractEmployee)enumSub.Current;
				sum += esub.getSalaries();
			}
			return sum;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -