i have a simple question when building a value object that has a collection of value objects inside it with a specific type how do you construct the object ?
to take an example lets say you have a picture
that take multiple dimensions
Option 1 :
Class Picture implements valueObject{
public function __construct(array $dimensions){
foreach($dimensions as $dimension){
// check if instance of `dimension` value object
}
}
}
Option 2 :
Class Picture implements valueObject{
public function __construct(DimensionCollection $dimensions){
}
}
Class DimensionCollection implements Traversable{
public function add(Dimension $dimension){
// add to array
}
}
Option two off-course seems more logical but is there another pattern that is better taken this from DDD preceptive ?