Re: [Vala] Understanding object creation (and other things)




The only sensible possibility to make this simpler would be to allow
accessing the construction parameters in the constructor, maybe
something like that:

class Mul {
        private int answer;

        public int get_answer() {
                return answer;
        }

        public void set_terms(int x, int y) {
                answer = x * y;
        }

        public Mul(construct int x, construct int y) {
        }

        // implicitly declare construct-only parameters x and y
        // with a default value of -1
        construct (int x = -1, int y = -1) {
                set_terms(x, y)
        }
}

Would something like that make sense?

It does to me.  In fact, that seems to bridge most of the gap between
Vala syntax and other languages.  What I do worry about, is that it
doesn't help to really clarify a correct method for doing this sort of
thing.  I'm sure when there is some documentation it will be a lot
easier, but at the moment it's very hard to feel sure about things
like what functions will be called when creating a subclass.

The way I'd implement such a class currently is by using a helper method
for construction - assuming that you don't want to create instances of
subtypes in the same manner.

That's definitely an option in this case.  The problem is of course as
you said, inheritence...

Jürg




--
Phil Housley


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