C # (OOP) Nested business objects

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.

+3
5

-?

.

- , . -, -. - -. , . , , . -, .

, , , .

+8

, , .

, , , .

0

, Employee (.. ), , . (, ) , "" Employee, .

0

, - ( ) :

    /// <summary>
    /// Manufacturer Data Transfer Object
    /// </summary>
    public class MfgBO {
        public int Id { get; set; }
        public string Name { get; set; }
        public bool Active { get; set; }
    }
  }

public class TypeBO {
        public int Id { get; set; }
        public string Name { get; set; }
        public bool Active { get; set; }
    }


 public class ModelBO {
        #region Private Variables

        private int mmtId = -1;
        private int id = -1;
        private string name = String.Empty;
        private bool active = false;
        private MfgBO mfg = new MfgBO();
        private TypeBO type = new TypeBO();

        #endregion
        // Getter and setters below

, ModelBO MfgBO TypeBO, . , , ModelBO MfgBO TypeBO, int MakeID, MakeName, int DeviceTypeId, DeviceTypeName .., , MfgBO TypeBO.

MfgBO TypeBO. ? MfgBO TypeBO MakeBO " "?

0

, .

public BusinessObject Item
{
    get
    {
        if (_Item == null)
            _Item = new BusinessObject();

        return _Item; 
    }
}
private BusinessObject _Item;  
0

Source: https://habr.com/ru/post/1715584/


All Articles