-
Notifications
You must be signed in to change notification settings - Fork 171
Improve API for cloning/creating rectangles #2186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve API for cloning/creating rectangles #2186
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking at this PR together with its first usage (eclipse-platform/eclipse.platform.ui#3005) and I have some questions (it might be that there are more consumers that haven't been adapted yet so I might be missing "the big picture", feel free to comment on that :-) ):
- Do we really need the interface
MonitorAware
? How is it helpful? - I would remove the new method
copyWith(...)
if it's only necessary to copy and modify the receiver since that is something that the consumer can do on its own without "special handling" (no monitor-awareness, zooms, etc seem to play a role here) - I see that
Copyable
is merely a "better named version ofCloneable
" and it was probably added so that the methodscopy()
andcopyWith(...)
are associated with each other (?) . If that's the case, I think getting rid ofcopyWith(...)
and replacingCopyable
withClonable
is really a valid option.
bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/MonitorAware.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/MonitorAwareRectangle.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/MonitorAwareRectangle.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java
Outdated
Show resolved
Hide resolved
c4be5d7
to
dcb6310
Compare
Cloneable has clone() method as protected. If it is fine to override it to public without breaking the API conventions of SWT, I can use that for sure. |
e113616
to
c5f86dd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, the change looks reasonable to me. Having proper clone functionality for those data classes is fine. I am not sure whether we can have a more expressive name for Rectangle.of
.
Cloneable has clone() method as protected. If it is fine to override it to public without breaking the API conventions of SWT, I can use that for sure.
Note that Cloneable has not clone()
method at all. clone()
is defined by Object
in Java and needs to be overwritten and made public in classes that implement the Clonable
interface. I don't see that this can conflict with any conventions or contracts in SWT. Rectangle
cannot be extended, so there is not chance that there is a conflicting overwrite of the method.
bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/MonitorAwareRectangle.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java
Outdated
Show resolved
Hide resolved
Just an idea: Do we really need an own class here? Can't we add a (package protected?) field to the regular |
60dbf84
to
1c2b80a
Compare
bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java
Outdated
Show resolved
Hide resolved
The class already exists. This change just adds further functionality. Back then, we also discussed adding a field to the existing
|
If that holds true then one should actually not extend Rectangle but e.g. use a record that combines a rectangle with a monitor. |
If it's not a subclass, you cannot pass it via existing APIs that accept or return instances of Rectangle. |
The obviously the monitor is an important property in some cases and there are only others where it is irrelevant. This is similar to how we do it with So either we should have new API that accepts a Point/Rectangle + Monitor or we should account for the fact that the monitor is a property of a Rectangles or point. Having only internal used classes with marker interface and trying to restrict what we made public seems not very useful and complicates the matter more than it solves it. |
Why? And what's the marker interface here? |
This commit contributes to providing better interfaces and APIs for cloning/creating rectangles, including the proper consideration of subclasses like the monitor-aware implementation of Rectangle. Contributes to eclipse-platform#62 and eclipse-platform#128
1c2b80a
to
34884b2
Compare
34884b2
to
128175b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've corrected wrong code formatting and added the necessary version bump commit, as a minor bump for SWT is required due to added API.
This PR contributes to providing better interfaces and APIs for handling MonitorAware Rectangles and Points with Abstraction using prototype pattern.
All the Monitor Aware classes implement MonitorAware. Also th coordinate classes liek Rectangle and Point implement an interface copy. This should be introduced as a convention to use copy or copyWith, when a consumer wants to create a new object from the existing one. If there's any offsetting needed, the method copyWith can be used, making sure we copy all the abstract fields of the underlying Child class (if applicable) to the new object.
Also this PR introduces a new method Rectangle.of(Point, int, int) to make it easy to create rectangles using points instead of calling the Rectangle Constructor.
contributes to
#62 and #128