Re: [Vala] Question about namespaces..

On Wed, Jan 06, 2010 at 12:22:49 -0700, Shawn Ferris wrote:
On Wed, 2010-01-06 at 07:51 +0100, Jan Hudec wrote:

It already exists. It's called a class!

Of course I know what a class is, and I understand (mostly) what they're
capable of. The problem with a separate class to manage the plugins is
scope. (IMO)

Scope behaves exactly the same with namespaces and classes except for the
fact you can't add to a single class from multiple files while you can add to
a single namespace from them. And that's only until Vala implements 'partial'
like in C#.

I wanted to suggest you convert the namespace to class (you can have
inner classes just fine) or create new class, but now I see you can
just as easily abuse the class you already have. Just make the array
a static field of the MyApp.Plugin.Instance class and make the "current"
property a class property of the same (static will do if you only call
it after any plugin is registered).

To convert the namespace to a class would require every plugin to then
know where the manager metaspace is, just so that it could instantiate
itself. That sounds like a pain, if not a bad idea.

It needs to know *anyway*.

A class is a namespace plus a structure definition, class structure
definition and a singleton class structure instance. And nothing more!

If you take a namespace, replace the 'namespace' keyword with 'public class'
and prepend 'public static' to all declarations inside it, you'll get an
exact equivalent (with a couple of useless extra definitions) of the
namespace. The only difference being that you now can't 'use' it, but can
inherit it instead.

You may also consider writing an interface instead of class. Interface can't
have fields, but it can have static fields and both static and instance
methods including implementations *and* can be multiply-inherited by the
plugin (though it really makes more sense to delegate from the plugin

                                                 Jan 'Bulb' Hudec <bulb ucw cz>

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