Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4080774
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:58:24+00:00 2026-05-20T17:58:24+00:00

I have such a funny question. I have the following architecture: For example, Manager

  • 0

I have such a funny question.

I have the following architecture:

For example, Manager class is implemented like this:

public sealed class Manager : Interface.Abstract.Employee
{
    private Interface.IEmployee chief = null;
    private readonly Decimal bonuslimit = Convert.ToDecimal(0.4F * Convert.ToSingle(BaseSalary));

    public Manager(Person person, DateTime hiredate) 
    : base(person, hiredate)
    {
    }

    public override List<Interface.IEmployee> Subordinates
    {
        get;
        set;
    }
    public override Interface.IEmployee Chief
    {
        get
        {
            return this.chief;
        }
        set
        {
            //if(value is Associate)
            //{                    
            //    throw new SystemException("Associate can't be a chief");
            //}
            this.chief = value;
        }
    }
    public override Decimal Salary
    {
        get
        {
            var actualbonus = Convert.ToDecimal(0.01F * Convert.ToSingle(this.YearsSinceHired * BaseSalary));
            var bonus = (actualbonus > bonuslimit) ? bonuslimit : actualbonus;
            var additional = 0M;

            if(this.HasSubordinates)
            {
                foreach(Interface.Abstract.Employee employee in this.Subordinates)
                {
                    if(employee is Sales)
                    {
                        additional += employee.Salary;
                    }
                } 
            }
            return Convert.ToDecimal(Convert.ToSingle(additional) * 0.005F) + BaseSalary + bonus;
        }
    }
}

And ‘factory client’ that looks like this:

public class EmployeeFactoryClient
{
    private IDictionary<String, IEmployee> employees = new Dictionary<String, IEmployee>();              

    public EmployeeFactoryClient()
    { 
        this.Factory = new EmployeeFactory();            
    }
    public EmployeeFactoryClient(IEmployeeFactory factory)
    {
        this.Factory = factory;            
    }
    public IEmployeeFactory Factory { get; set; }

    public void HireEmployee(Person person, String type, String code)
    {
        this.employees.Add(
            new KeyValuePair<String, IEmployee>(
                code,
                this.Factory.Create(person, type, DateTime.Now)
            )
        );
    }
    public void DismissEmployee(String code)
    {
        this.employees.Remove(code);
    }
    public IEmployee GetEmployee(String code)
    {
        return this.employees[code];
    }
    public IEmployee this[String index]
    {
        get { return this.employees[index]; }
        private set { this.employees[index] = value; }
    }

    public Decimal TotalSalary
    {
        get
        {
            var result = 0M;
            foreach(var item in this.employees)
            {
                result += item.Value.Salary;
            }
            return result;
        }
    }        
}

And finally I have some test code:

public void SalaryTest()
    {
        #region [Persons]            
        var SalesPerson01 = new Person
        {
            Birthday = new DateTime(1980, 11, 03),
            Forename = "Corey",
            Surname = "Black",
            Gender = SexType.Female
        };
        var SalesPerson02 = new Person
        {
            Birthday = new DateTime(1980, 11, 03),
            Forename = "John",
            Surname = "Travis",
            Gender = SexType.Male
        }; 
        #endregion

        this.company.HireEmployee(SalesPerson01, "Sales", SalesPerson01.GetHashCode().ToString());
        ((Employee)this.company[SalesPerson01.GetHashCode().ToString()]).YearsSinceHired = 10;

        this.company.HireEmployee(SalesPerson02, "Sales", SalesPerson02.GetHashCode().ToString());
        ((Employee)this.company[SalesPerson02.GetHashCode().ToString()]).YearsSinceHired = 3;            

        ///////////////////////////////////////////////////////////////////
        ((Employee)this.company[SalesPerson01.GetHashCode().ToString()]).Subordinates.Add(
            this.company[SalesPerson02.GetHashCode().ToString()]
        );

        Assert.AreEqual(1405M, this.company.TotalSalary);
    }

Line
((Employee)this.company[SalesPerson01.GetHashCode().ToString()]).Subordinates.Add(this.company[SalesPerson02.GetHashCode().ToString()]); throws NullReferenceExeption. In the this.company[SalesPerson02.GetHashCode().ToString()] indexer returns IEmployee interface but not a class instance. Am I right? And if it is so how do I fix that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T17:58:24+00:00Added an answer on May 20, 2026 at 5:58 pm

    I don’t see anywhere that you are initializing the Subordinates member, so I suspect that it still has the default value which is null (not the empty list). The fix is to initialize it to an empty list in the constructor:

    public Manager(Person person, DateTime hiredate) : base(person, hiredate)
    {
        Subordinates = new List<Interface.IEmployee>();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such a class: public class Cycle { public List<int> Edges { get;
I have such class public unsafe class EigenSolver { public double* aPtr {get; private
I have html which contains such text ....... <a class=product_name href=index.php?productID=29785>Funny</a> ........ <a class=product_name
have such zend query: $select = $this->_table ->select() ->where('title LIKE ?', '%'.$searchWord.'%') ->where('description LIKE
I have such singleton structure: // Hpp class Root : public boost::noncopyable { public:
I have such html and css. <div class=selected> <div class=text>First</div> <div class=arrow>&nbsp;</div> </div> .selected
I have such text: <Neednt@email.com> If you do so, please include this problem report.
When developing I like to have strongly typed objects for certain values. An example
have such kind of error. When adding Redirect 301 rule to .htaccess file like:
I have such a funny problem I thought I'd share with you. I cornered

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.