Can model classes contain methods and constructor

Q : "Can model classes contain methods and constructor?" [BEST PRACTICE]

I have a class of employees, which consists of the name of the employee, age, salary, etc.

public class Employee
{
    public string Name { get; set; }
    public int Age { get; set; }
    public int Salary { get; set; }
}

can the above Model Classcontain some self-updating methods (for example, update the employee’s age every 1 hour with a timer or something] and / or constructors, or is it better to handle all these things from the executor?

+4
source share
3 answers

, ( DSL), , . u auto, getter, , , .

+4

? : . , , - , , , .

. " 1 -" . , - . - . , Age .

+5

It all depends on how the class is used.

There is nothing in the language that does not allow. But depending on what framework you use, and how you use classes in your code, where to place different functionality.

There is no better answer for every situation.

0
source

All Articles