RFR: 8345261: Refactor the Dimension2D classes
Nir Lisker
nlisker at openjdk.org
Thu Mar 6 02:54:58 UTC 2025
On Mon, 2 Dec 2024 14:34:08 GMT, Alexander Zvegintsev <azvegint at openjdk.org> wrote:
>> Thanks @azvegint. If the `int`-based dimensions are coupled with `com.sun.javafx.geom.Rectangle` (and from the code, that's the only place they are used at), would you object to making `Dimension` an inner class of `Rectangle`? The `float`-based dimensions are used in other 2D shapes, so are more general purpose.
>
>> would you object to making Dimension an inner class of Rectangle?
>
> I am fine with it.
> > Thanks @azvegint. If the `int`-based dimensions are coupled with `com.sun.javafx.geom.Rectangle` (and from the code, that's the only place they are used at), would you object to making `Dimension` an inner class of `Rectangle`? The `float`-based dimensions are used in other 2D shapes, so are more general purpose.
>
> In my opinion, inner classes are justified when the implementations are coupled, or when one thing only makes sense in the context of another thing. That doesn't seem to be the case here: `Dimension` is neither used in `Rectangle`, nor are their implementations coupled.
>
> What this suggests to me is that either `Dimension` should remain its own top-level class, or if it is not useful there, be moved to where it _is_ used instead.
The int-based Dimension is only used *by* `Rectangle` even if in another class. I can couple their implementations by adding a `Rectangle#asDimension2D`, and this will be the only instantiation of this class. Note that there's already a constructor `Dimension2Di(Rectangle rect)` that instantiates only via the enclosing class.
-------------
PR Comment: https://git.openjdk.org/jfx/pull/1653#issuecomment-2702651232
More information about the openjfx-dev
mailing list