priya gopi

priya gopi

  • NA
  • 2
  • 2.3k

Decorator pattern

Jul 20 2012 1:00 AM
Hi,

I have a class like this

public class OrgChartBasicInfo
    {
        public int UserId { get; set; }
        public int ManagerUserId { get; set; }
        public string FullName { get; set; }
        public string CompanyName { get; set; }
        public string CurrentPosition { get; set; }
        public string PhotoUrl { get; set; }
        public string Location { get; set; }
    }

Am adding these values to a List like this

private static List<OrgChartSuccessor> GetSuccessors()
        {
            List<OrgChartSuccessor> Successors = new List<OrgChartSuccessor>();
            OrgChartSuccessor SuccessorInfo = new OrgChartSuccessor();
         
            SuccessorInfo.UserId = 1;
            SuccessorInfo.RiskOfLossLabel = "Images/orgchart-icon-lowrisk.png";
            SuccessorInfo.RiskOfLossTitle = "Risk of Loss Title";
            SuccessorInfo.RiskOfLossReason = "RiskOfLossReason";
            SuccessorInfo.PhotoUrl = "../Images/orgchart-mondrian-medium.jpg";
            SuccessorInfo.FullName = "Successor1";
            SuccessorInfo.CurrentPosition = "Reg. Director of Sales ";
            SuccessorInfo.Location = "Atlanta, GA";
            Successors.Add(SuccessorInfo);
            return Employees;
        }

I want to add ChildInfo=1 also in to my list without modifying my class
I did it like this,

  public class OrgChartBasicInfoEx : OrgChartBasicInfo
        {
            public int Collapsed {ger;set;}
        }
  private static List<OrgChartBasicInfo> GetEmployees()
        {
            List<OrgChartBasicInfo> Employees = new List<OrgChartBasicInfo>();
            OrgChartBasicInfoEx ChildInfo = new OrgChartBasicInfoEx();
            ChildInfo.UserId = 1;
            ChildInfo.ManagerUserId = 0;
            ChildInfo.FullName = "Employee1";
            ChildInfo.CompanyName = "Abc Company";
            ChildInfo.CurrentPosition = "Reg. Director of Sales ";
            ChildInfo.Collapsed = 1;
            Employees.Add(ChildInfo);
            return Employees;
        }
But its not adding that value to my collection as the collection is taking from "OrgChartBasicInfo" I cant modify these classes as it is given by my client
Please give me any other solution to add an additional property to my collection without modifying my class..I heard about Decorator class and something like Factory class .Can anybody tell me how can i solve my issue?

Thanks,
Priya