Module Conventions - Part 2 - Naming Conventions

This should be a quick blog entry to document some of the conventions I have used in the framework to get a handle on Javascript module management for model addins.

Element Naming Convention

As discussed here, all the element based creator functions for module addins are available at the global scope, so every class knows about every other class, hence polluting the global namespace.  Therefore the naming of classes needs to be carefully considered to avoid clashes.

The scheme I have used is to build the namespace for each module into the name of the element.  For example, the module with namespace "ser.ea.element" is called "ser_ea_element".  That is, the dots (.) have been replaced by dashes (_).

I'm not entirely happy with this workaround.  I've got a few ideas to have something different but they will probably require further customisation within EA, and a fair amount of experimentation.  For the moment, this naming workaround will suffice.

EA Wrapper Modules

A large part of the framework is a set of wrappers around the standard automation objects.  In the user guide the automation objects are grouped under packages - see here for the automation packages documented in the user guide.

I have used the same package structure to make things easier for users of the framework.  For example, the "Repository" package, documented here in the user guide, has the corresponding wrapper module with namespace "ser.ea.repository", and a class element called "ser_ea_repository".  The class element implements a getModule() operation which returns the module object.

Types, Factories and Singleton Objects

Some of the Javascript code I've come across tends to mix classes/types, factory methods and object instances (often singletons).  The following conventions are probably not Javascript idiomatic and probably highlight my code structuring prejudices and idiosyncrasies.

  • Types, classes and creator functions are available as attributes of the module object for a particular namespace.  For example, within the namespace ser.ea.repository, the framework equivalent wrapper class is available as ser.ea.repository.RepositoryWrapper.
  • All modules within the framework have a factory class that can be used to create objects for the module - it is usually called "Factory" for every module.
  • If a module needs to expose singleton objects, these are provided in a separate, but consistently named ("context") namespace.  For example, the framework wrapper for the Repository object is available from ser.ea.context.

Comments

Popular posts from this blog

Creating Items in Sparx EA via Java

Flexible Method Pattern

Traversing a EA Model via Java