In the linked example, the structure of the contract that is created by the factory contract is specified in the same source code file as the factory contract that creates it. The compiler (solc) will compile the source code of the created contract, and then compile the factory contract so that it knows how to create a contract with that compiled code.
A contract can create a contract with arbitrary data (which becomes the child contract's code) so in theory it should be possible to build code dynamically inside the factory contract then instantiate a contract using that code. But it is probably not practical to actually compile code inside a contract, which would require a Solidity compiler written in Solidity.
There may be some weird situations where you want to build compiled code with some initial variables set dynamically in your contract, then use that data to instantiate a contract, but it would be an unusual thing to do. Usually you want to define the structure of the contract in advance (or several different contracts, if you have several different patterns) in normal source code and instantiate an instance of the predefined contract, then call the newly-created contract to set your initial variables that will affect its behaviour.