Re: Object properties



Russell Shaw wrote:

Hi,
In a widget, should an object property of the widget be accessed directly,
or with g_object_get()/set() ?

Hello, Russel

What do you mean on "directly" ? I see two possible cases:
1) The direct access to the specific field of widgets structure.
2) Use of widget's supported wrappers like 'gtk_*_[gs]et_*()'.

The first case is not good because:
* widget implementation may change in future and you'll have to modify code;
* you have to support notification on changed property.
The only possible place for such things IMO is a widget implementation code.

The second case:
+ code is little more readable;
+ code will work somewhat faster (no need in GObject code that makes checks and calls [gs]et_property widgets methods); + wrappers are better documented ;), so its easier for others to learn your code; - wrappers support access to the single property only, when with g_object_[gs]et you can change multiply properties at one call; - wrappers sometime sound different from properties: gtk_toggle_button_set_mode() modify "draw_indicator" property, gtk_widget_show()/gtk_widget_hide() modify "visibility" property.

   Olexiy





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]