how can you define the number of different objects to create?

    protected void CreatePersonInstances(int employeeCount, int managerCount, int recruiterCount)
    {
        //some validation to check count number not negative

        ExampleList.AddRange(Enumerable.Range(0, employeeCount).Select(x => new Employee()));
        ExampleList.AddRange(Enumerable.Range(0, managerCount).Select(x => new Manager()));
        ExampleList.AddRange(Enumerable.Range(0, recruiterCount).Select(x => new Recruiter()));
    }

where Employee, Manager and recruiter inherit from Person entity


    public class Person
    {
        public string Name { get; set; }
    }

    public class Employee : Person
    {
        public int EmployeeId { get; set; }
    }

    public class Manager : Person
    {
        public int ManagerId { get; set; }
    }

    public class Recruiter : Person
    {
        public int RecruiterId { get; set; }
    }

Besides the scope of the question, this whole model is a good use case for the Factory Design Pattern. If you havent, check it out 👍

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top