I'm a fan of keeping things simple. This enhances readability and the usability of an API. I don't think there's a definitive answer, But I would go for the second approach, although I would call the method context.addError(object, error)
, for this implies, that their could be more than one error, which is the case, when I look at your possible implementation.
The getError(object)-approach lacks good naming too, I think. If you choose the first approach consider naming the Method getErrorHolder(object).getError()
.
EDIT: If I still get you wrong, that's a sign for ambigious naming. Use add
for adding to a Collection and set
for single instances.