oo-70-245-1

oo-70-245-1 Commit Details


Date:2015-10-26 20:28:27 (8 years 11 months ago)
Author:Natalie Adams
Branch:master
Commit:d4b301bb30924d8c5f10758b9cb30c830086de89
Parents: c357ea3885b338f6d2f39aea4b01d9ebc6699425
Message:Adding composite example

Changes:

File differences

compositeClassExample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace compositeexample
{
public interface IEmployed
{
int EmpID { get; set; }
string Name { get; set; }
}
public class Employee : IEmployed, IEnumerable<IEmployed>
{
private List<IEmployed> _subordiantes = new List<IEmployed>();
public int EmpID { get; set; }
public string Name { get; set; }
public void AddSubordinate(IEmployed subordiante)
{
_subordiantes.Add(subordiante);
}
public void RemoveSubordinate(IEmployed subdorinate)
{
_subordiantes.Remove(subdorinate);
}
public IEmployed GetSubordinate(int index)
{
return _subordiantes[index];
}
public IEnumerator<IEmployed> GetEnumerator()
{
foreach (IEmployed subordinate in _subordiantes)
{
yield return subordinate;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
public class Contractor : IEmployed
{
public int EmpID { get; set; }
public string Name { get; set; }
}
class Program
{
static void Main(string[] args)
{
Employee Rahul = new Employee { EmpID = 1, Name = "Rahul" };
Employee Amit = new Employee { EmpID = 2, Name = "Amit" };
Employee Mohan = new Employee { EmpID = 3, Name = "Mohan" };
Rahul.AddSubordinate(Amit);
Rahul.AddSubordinate(Mohan);
Employee Rita = new Employee { EmpID = 4, Name = "Rita" };
Employee Hari = new Employee { EmpID = 5, Name = "Hari" };
Amit.AddSubordinate(Rita);
Amit.AddSubordinate(Hari);
Console.WriteLine("EmpID={0}, Name={1}", Rahul.EmpID, Rahul.Name);
foreach (Employee manager in Rahul)
{
Console.WriteLine("\n EmpID={0}, Name={1}", manager.EmpID, manager.Name);
foreach (Employee emp in manager)
{
Console.WriteLine(" \t EmpID={0},Name={1}", emp.EmpID, emp.Name);
}
}
}
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.05695s using 14 queries.