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

Re: [Vala] private fields vs bodyless properties



On Fri, 2008-05-30 at 10:46 +0200, Juerg Billeter wrote:
> On Fri, May 30, 2008 10:28, Yu Feng wrote:
> > On Fri, 2008-05-30 at 06:57 +0200, Jaap A. Haitsma wrote:
> >> The reason for this is that the objects are gobjects and these are
> >> created by a g_object_new call [1]. That function can only set
> >> properties. So you need to have a property if you want to pass data to
> >> your constructor
> >>
> > However the following code is perfectly fine;
> >
> > MyObject * my_object_new(int my_value){
> >   MyObject * myobject = g_object_new(TYPE_MY_OBJECT, NULL);
> >   MyObjectPrivate * priv = MY_OBJECT_GET_PRIVATE(myobject);
> >   priv->my_value = my_value;
> > }
> > (I think I am also using this when writing c programs)
> 
> We don't allow this as it will break subclassing, i.e. subclasses can't
> assign anything to my_value, and it will also break bindings that call
> g_object_new directly.
> 

You are right my code was a bad behavior. If something should be
initialized when creating the instance, it has to be a property.


> Juerg
> 



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