Today I received the following letter from an employee. My question is so exact. Nesting Business Objects - Bad Practice? Can anyone highlight this?
Nested Objects When a variable is created in C #, it takes up some of the memory on the web server. Since we will have many tools running on the same server, it is even more important to ensure that we do not create objects if we do not plan to use them.
Using the second worker object as an example above ... If we also needed to know the employees of the Supervisor ID .. (and this was the whole tool for filling and using), we would like the Employee class to contain the relevant information, along with memory and processes in the tool.
We will add the supervisorId string variable to the Employee class and add the corresponding Getters and Setters.
On the flip side, we would like to avoid nesting another object in an employee object. Such as: public class Employee {private string firstName; private string lastName; private string empId; private head of the personnel department;
public string FirstName {
get { return firstName; }
set { firstName = value; }
}
public string LastName {
get { return lastName; }
set { lastName = value; }
}
public string EmpId {
get { return empId; }
set { empId = value; }
}
public Employee Supervisor{
get { return supervisor; }
set { supervisor = value; }
}
}
In this case, we cannot always use the values in the Supervisor instance of the Employee object, but the variables are created in memory. This can have a potentially catastrophic effect on performance.
There are “some” cases where an attachment of objects is required: Example: (Category :: Question). In each category there can be a list of arrays assigned to it.
x2ws