[Vala] Question about namespaces..



Hey All

Firstly, I'd just like to say that I'm having a lot of fun writing in
Vala. I am learning a ton and thanks to everyone for making it happen.
It's a very cool language!

Now the question. Well, more of a thought. Perhaps this is even possible
already, and I'm just not finding it in the documentation. Regardless, I
was trying to develop something like a plugin manager and keep
everything related to the plugins under a nested namespace. (IE:
MyApp.Plugin)

I'd then have a class (MyApp.Plugin.Instance) that the plugins would
inherit from and automatically control some of the setup. I also needed
a way to track the order in which the plugins were registered, and more
importantly, the notion of a current plugin. (This is not exactly a
plugin manager, but it was the best example I could relate to)

So, I created an ordered type hash structure in MyApp.Plugin to track
all the instantiated plugins. And then figured a property would handle
the current plugin by just returning the first element in the ordered
hash. This way there's no need to shuffle a variable when plugins are
unregistered/unselected. It's just removed from the ordered hash, and
viola, current will automatically reference the next one in line.
(Obviously, I didn't realize right away that namespaces couldn't contain
properties, which is not really a problem either, because I just
replaced it with a method instead)

.. but then someone posted a message regarding Singletons, and I'm
thinking, why couldn't namespaces be Singleton Objects? Instead of
instantiating it with new, they could be initialized. (EG: initialize
Namespace;) Even better, perhaps we don't have a choice, it just gets
initialized upfront?

Seems to me, it'd be useful.. or am I just kidding myself? or worse,
designing bad code? 8D

Regards,
Shawn






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