Implementing static methods

The use of specific JADE features and proposals for new feature suggestions
allistar
Posts: 156
Joined: Fri Aug 14, 2009 11:02 am
Location: Mount Maunganui, Tauranga

Implementing static methods

Postby allistar » Wed Apr 14, 2010 12:05 pm

Hi all,
Alas, Jade does not allow for static methods. There are often times though when a static method is the best way to implement a particular feature or help provide for a more extensible framework.

So how do we implement a workaround to static methods?

Options I see are:

1) use normal methods and create a transient instance of the class and call that method.
- won't work for abstract classes.
- has an inherent performance hit in creating the transient, especially when called many times. This could be mitigated by using a flyweight pattern, but then you'd have a additional dictionary lookup to get the flyweight object.

2) write a method on the Class class that does a large case-like if statement.
- not very nice.
- you cannot just compare classes with classes, you need to compare class names because of subschema copy classes have a different oid.
- need to work out the subclasses and/or superclasses of "self", which will require a transient dictionary. Not very efficient.

3) Create a user class that represents the Jade class and have "myParentClass", "allChildClasses", "name" properties and create an instance of that class for every class in your schema(s). Store these in a globally accessible collection keyed by class name. Put your "static" method on this and inside it have a large case-like if statement. The "default" of the case statement would be do call the same method on myParent.
- a pain to have to set up.
- will need to have the persistent parallel class structure maintained and kept in sync.
- at least it would be relatively efficient.

Are there any other (hopefully nicer) ways of implementing pseudo-static methods in Jade? The key is it needs to be efficient at runtime.

Return to “Feature Discussions”

Who is online

Users browsing this forum: No registered users and 13 guests

cron