Re: Accessors vs Properties
- From: Debarshi Ray <rishi is lostca se>
- To: Tobias Knopp <tobias knoppweb de>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Accessors vs Properties
- Date: Thu, 5 Jan 2017 10:05:21 +0000
On Tue, Jan 03, 2017 at 10:46:13PM +0100, Tobias Knopp wrote:
- Is any accessor backuped with a property and vice versa?
Nicola already answered this.
- Which one is to prefer?
It depends.
For simple setting and getting of values from C, I prefer the
accessors because (a) it lets the compiler do some minimal type
checking (b) accessors are more efficient at returning a C string than
g_object_get. However, you need properties if you want to have a
'parametrized constructor'. ie. pass arguments to a *_new function.
Properties are more convenient from higher-level languages. eg., in
JavaScript, you can use my_obj.prop to access a property.
They also offer extra features:
(a) You can bind a property on one object to another property
elsewhere (see g_object_bind_property*).
(b) Every property comes with its own 'notify' signal that you can use
to listen for changes.
(c) They can be introspected at run-time, which is very useful if you
are writing a tool like the gtk+ inspector, glade or d-feet.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]