wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver B. Fischer" <mails...@swe-blog.net>
Subject Re: Why is getDisplayValue in getDisplayValue final?
Date Mon, 13 Jan 2014 09:41:37 GMT
I see your point and I also think that it is very important to ensure 
the contract your class or methods relies on.

But in such a case the method where the method must be final a 
customization point should be provided to allow us the modify the part 
of the method which is independent of the contract.

For example:

@Override
public final Object getDisplayValue(T object)
{
   final String value = getDisplayValueRaw(object);

   return postprocess(value);
}

getDisplayValueRaw() whould be the customization point and could be 
overwritten by a developer without breaking the method contract.

Oliver


Am 09.01.14 00:12, schrieb Igor Vaynberg:
> the method is final because overriding it means you will most likely
> break the contract of the resourceKey and postprocess methods which
> are meant to be used by you to customze the behavior of
> getDisplayValue().
>
> so lets say you create subclass MyEnumChoiceRenderer with an
> overridden getDisplayValue() that no longer calls postprocess(). then
> someone subclasses your subclass and overrides postprocess() expecting
> it to be called (thats what the javadoc says) but it wont be, because
> you broke the contract.
>
> having getDisplayValue() be final prevents you from breaking this
> contract and saving hours of head scratching down the road.
>
> if you look at EnumChoiceRenderer without getDisplayValue() there is
> only one meaningful line of code left:
>
> return Classes.simpleName(object.getDeclaringClass()) + '.' + object.name();
>
> everything else is javadoc or declarations. so why all the fuss over a
> trivial line of code?
>
> -igor
>
> ps: ironically if you did want to override getDisplayValue() in a way
> that broke the contract you would have to make your subclass final so
> no one further down the road could subclass it...
>
>
> On Tue, Jan 7, 2014 at 6:37 AM, Oliver B. Fischer <mailsink@swe-blog.net> wrote:
>> Hi,
>>
>> I just tried to customize EnumChoiceRenderer and to override
>> getDisplayValue, but is final. Why?
>>
>> Can I submit a patch to remove final?
>>
>> Bye,
>>
>> Oliver
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Mime
View raw message