Re: [Vala] How to get the base class name with out the spacename?



i'm implementing a simple ORM model,  which will crate the table refer
to the class name


namespace PlatformX {
    public class User () {
            .....// with create a database table named user or users
    }
}



在 2015年11月16日 02:24, Al Thomas 写道:
From: Matrix <pigex zhang gmail com>
Sent: Sunday, 15 November 2015, 14:45
Subject: [Vala] How to get the base class name with out the spacename?

Hi :

i want to get the base class name with out the spacename

for example :

namespace PlatformX {
    public class User () {
            this.get_type().name();
    }
}

the name is PlatformXUser not User .....

any methods to query this ?

Why would you want to do that?

Class names should be for programming, not presenting nicely formatted strings.
It makes sense to prepend the namespace. This avoids any name conflict with another
class of the same name, but in a different namespace.

If you are looking to create multiple classes of the same name, but each doing
things in a different way, then you want to be using interfaces. That way each
class has a unique class name, but the interface it implements is the same name.
This is how you achieve polymorphism in Vala. There is then nothing stopping you
from using the interface name as the type in a methods parameters. This allows
you to pass different classes of object to the method, so long as they implement
the common interface.

Hope that makes sense,

Al



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