The Constructor of the ValueCreationException
performs an automatic lookup via the ErrorCodeMapper.
I consider it at least a drawback, because:
- the caller cannot employ a different strategy on
using the ErrorCodeMapper because the original error
code provided by the validating type is gone. There
is no getter for the original error code.
- this reduces the usability of the ErrorCodeMapper
because the developer may make extensive use of the
filters, hierarchies, etc but the constructor of the
ValueCreationException will always find the very
exact match (<valuetype class name>.errorcode) but
there might be other mappings as well (employing
filters or a more complex hierarchy).
- Object creation cost. The lookup is always
performed but the result might not be needed. The
constructor is build with the assumtion of the most
common case but all other cases will pay with extra
load. The lookup can easily be performed in the
dedicated getter itself.
Logged In: YES
user_id=1047029
Thanks Nico, it is a good idea to make the class
ValueCreationException more open for changes in possible
subclasses. This could be achieved by moving the mapping
functionality from the constructor to the method
getErrorCode() that can be redefined in a subclass.
I don't think the cost of calling the ErrorCodeMapper is
relevant as it's only called once. But I could do a lazy
initialisation call for _code in the getErrorCode()
methode and provide an extra method "getOriginalErrorCode
()" to access the unmapped code.
Logged In: YES
user_id=1047029
Thanks Nico, it is a good idea to make the class
ValueCreationException more open for changes in possible
subclasses. This could be achieved by moving the mapping
functionality from the constructor to the method
getErrorCode() that can be redefined in a subclass.
I don't think the cost of calling the ErrorCodeMapper is
relevant as it's only called once. But I could do a lazy
initialisation call for _code in the getErrorCode()
methode and provide an extra method "getOriginalErrorCode
()" to access the unmapped code.