I have a small question. Which approach is correct in the context of SOLID principles? 1 or 2 ?
In the first case, the "CreateTask" method does not return the Task object, but places it on the list that it accepts as the method argument.
In the second case, the "CreateTask" method does not accept arguments, but returns a task object that must be placed in the Tasks list
1.
var tasks = new List<Task>(); CreateTask1(tasks); CreateTask2(tasks); CreateTask3(tasks); private void CreateTask1(List<Task> tasks) { // some other logic about new task object tasks.Add(new Task()); } private void CreateTask2(List<Task> tasks) { // some other logic about new task object tasks.Add(new Task()); } private void CreateTask3(List<Task> tasks) { // some other logic about new task object tasks.Add(new Task()); } 2.
var tasks = new List<Task>(); tasks.Add(CreateTask1()); tasks.Add(CreateTask2()); tasks.Add(CreateTask3()); private Task CreateTask1() { // some other logic about new task object return new Task(); } private Task CreateTask2() { // some other logic about new task object return new Task(); } private Task CreateTask3() { // some other logic about new task object return new Task(); }