It's a toss-up between minimising duplicated code or having to bend API
and implementation to your will (and end up with API you don't
necessarily want in the process).

Very rarely would I suggest extending a control - only when the API
matches perfectly with what you're doing, and then that really means all
you're doing is a custom skin anyway. More often than not it makes more
sense to follow the famous advice of preferring composition over
inheritance, and when that fails just bite the bullet and roll your own
using the base Control API (if you want a reusable and skinnable /
stylable control) or Region (if you don't need to be skinnable).

-- Jonathan

On 5/12/2013 11:05 a.m., Pedro Duque Vieira wrote:
> OK, sounds reasonable. Too bad about the code duplication that will
> need to take place.
>
> Thanks Jonathan and thanks for the link.
>
> Regards,
>
>
> On Wed, Dec 4, 2013 at 9:39 PM, Jonathan Giles
> <jonathan.gi...@oracle.com <mailto:jonathan.gi...@oracle.com>> wrote:
>
>     It is likely significantly easier to simply roll your own control and
>     not try to coerce ButtonBase to support two labels.
>
>     For what it is worth, Paru and I talked about precisely this
>     control at
>     JavaOne 2012, which you can watch on YouTube here:
>     
> http://www.youtube.com/watch?v=ryUTSrGGnvo&list=PLKCk3OyNwIzvw-zzCMJ3xq5SgxL961IFE&index=38
>
>     -- Jonathan
>
>     On 5/12/2013 10:16 a.m., Pedro Duque Vieira wrote:
>     > Hi,
>     >
>     > I'm trying to create a new control to be used by other
>     developers. It is
>     > know as "Toggle Switch".
>     > You can see this control in android:
>     > http://ankri.de/switch-button-for-android-2-3-gingerbread/ in iOS:
>     > http://iosguides.net/ios-menus-comparison/ (search for "Toggle
>     Switch") and
>     > on Windows 8:
>     >
>     
> http://www.c-sharpcorner.com/UploadFile/83f858/manage-the-windows-8-sync-feature/
>     > (below
>     > "Step 2").
>     >
>     > My approach was to subclass ButtonBase which is itself a subclass of
>     > Labeled. The problem here is that Labeled only accepts one label
>     but the
>     > Toggle Switch needs two: one for the "on" state and another for
>     the "off".
>     >
>     > Any ideas on how to best approach this problem?
>     >
>     > Thanks in advance, regards,
>     >
>
>
>
>
> -- 
> Pedro Duque Vieira

Reply via email to