|
|||||||
| View Poll Results: Do you like the use of public properties for pre-render configuration options? | |||
| Yes |
|
11 | 28.21% |
| No |
|
4 | 10.26% |
| No, and I prefer changing the API |
|
24 | 61.54% |
| Voters: 39. You may not vote on this poll | |||
![]() |
|
|
Thread Tools |
|
#1
|
||||
|
||||
|
The decision to use public properties in Ext GWT was a decision that was made after much deliberation and discussion with the community. Currently, public properties are only used for pre-render options that are used before a component is rendered. Methods can be called at any time.
Here are the issues: 1. Ext GWT needs a way to allow components to be "configured" before rendering. 2. Many components have a large number of config options. 2. Any solution should be typed. No config.set("frame", true); 3. It should be easy to identify pre-render options. Possible solutions 1. Have a config object for each components that is passed in the component constructor: ContentPanelConfig cfg = new ContentPanelConfig(); cfg.setFrame(true); cfg.setCollapsible(true); panel = new ContentPanel(cfg) panel = new ContentPanel(); panel.getConfig().setFrame(true); 4. Using a naming syntax with config options: panel.setConfigFrame(true); panel.setCFrame(true); panel.setCCollapsible(true); panel.frame = true; panel.collapsible = true; All that being said, we are open for feedback and suggestions. If you have an opinion, please let me know what you are thinking. If I had to pick an option that did not use properties I would probably prefer method 4 as it seems the most natural. |
|
#2
|
|||
|
|||
|
Thanks for the clarification but I don't get it.
ContentPanelConfig cfg = new ContentPanelConfig(); cfg.setFrame(true); cfg.setCollapsible(true); panel = new ContentPanel(cfg) Shouldn't in this case ContentPanelConfig actually be in-lined in the ContentPanel? When you extend the ContentPanel you are inheriting all of the config options anyway. Why is there a need for ContentPanelConfig in the first place? What is wrong with plain panel.setFrame(true), panel.setCollapsable(true);? If by some reason public fields are needed, please just supply the getters and setters it will not spoil the Java Bean feeling but you will still get public fields. |
|
#3
|
||||
|
||||
|
I'd vote for private fields and public accessors.
Reasons:
As an addition, refactoring existing code in Ext GWT is reeeeealy easy. Just 1 click on every class in my IDE of choice ![]() |
|
#4
|
||||
|
||||
|
Darrell,
Personally, I like option 3. Have separate configuration objects that are accessible from the widgets themselves. That has the benefit of completely separating the pre-render configuration away from the widget itself while still making easily accessible from the widget. It also allows for the creation of a single configuration object that can used for multiple widgets that you want to all have the same configuration. Anyway, that's how I see it. Take it for what it's worth.
__________________
There are two types of people in the world:
|
|
#5
|
||||
|
||||
|
One thing I forgot. With public fields you can't add validations.
|
|
#6
|
|||
|
|||
|
Hi Darrell,
I'm happy with any of proposed syntaxes. My main concern is upward compatibility, The code shouldn't have to be changed because a property becomes dynamic.
__________________
Go Habs Go |
|
#7
|
|||
|
|||
|
+1 for option 4 for the same reasons that others have pointed out above. I'd also be happy with a standard setter that throws if it does not support being used after rendering as long as the javadoc states this clearly.
|
|
#8
|
||||
|
||||
|
I don't mind using public fields, however this breaks encapsulation and makes it more difficult to evolve the API.
I don't like the idea of a setter prefix. I vote for using protected (or private) fields with public mutators. This is how I think the code should look. /**
* <p>NOTE : pre render property</p>
* describe the property here
*/
public void setFrame(boolean frame) {
assertNotRendered();
this.frame = frame.
}
private boolean frame;
add into Component
protected void assertNotRendered() {
assert !isRendered() : "property can only be set before the component is rendered";
}
|
|
#9
|
||||
|
||||
|
I'd vote for what Cameron said.
|
|
#10
|
||||
|
||||
|
If public properties are so annoying to folks (as a java developer I see why, although as a groovy/python developer I really like them), I'd prefer either:
a) simple getters/setters, a la Swing (although I'm not too keen about that assertion code that Cameron is suggesting - too verbose) b) config object (option 1, I think) I don't know how intuitive option 4 would be - looks a kind of weird, but I haven't really tried it. |
![]() |
| Thread Tools | |
|
|