Factory method signature for cumulative root

I want to write a factory method to create an instance that is an aggregated root.

Should the method accept aggregated child entities and values ​​as created objects or accept only primitive types?

For example, if I had a Computer object consisting of a processor and a memory object, the factory method takes the form:

public Computer NewComputer(
    string computerName, 
    int processorCores, 
    int processorClockSpeed, 
    string memoryType, 
    int memoryRam) 
{
    ...
}

or

public Computer NewComputer(
    string computerName, 
    Processor processor, 
    Memory memory) 
{
    ...
}

Is it just a matter of taste, or are there any serious considerations here?

+3
source share
3 answers

" " - node . . : Computer factory, "aggregate root". , - - , " "...

+1

, , .

factory (, CreateProcessor() ), , .

, ComputerFactory ( ) , factory , , .

+2

Factory ( ):

  • , - , , .
  • public Computer(string computerName, IProcessor processor, IMemory memory) 
    {
    }
    

. .

.

, , , . :

+1

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


All Articles