i18n API implementation issues

Allen Wirfs-Brock allen at wirfs-brock.com
Wed May 18 17:55:49 PDT 2011

On May 18, 2011, at 5:06 PM, Nebojša Ćirić wrote:

> If I remove constructor LocaleInfo.DateTimeFormat  where would I put LocaleInfo.DateTimeFormat.prototype.format() method for example (I would gladly remove the duplication, but I am not sure how)? Right now I do:
> LocaleInfo.prototype.dateTimeFormat(settings) {
>   return new LocaleInfo.DateTimeFormat(settings, this);
> }
> and
> LocaleInfo.DateTimeFormat = function(settings, locale) {
> }
> does actual work of creating the new object.

Clearly I'm being sloppy by having first not read your entire API; but of course actually developer also probably will jump in without reading everything so may it isn't such a bad approach....

I would expect that the LocaleInfo instance you obtained (I'll call it locale) has been instantiate for some specific "locale"  (in quotes I mean the abstract concept of some specific locale). In other words locale encapsulates all the knowledge that is needed to perform operations in some specific "locale" context.  Part of that encapsulated knowledge is what kind of DTF to use by default for that "locale" or how to selection from a set of possible DTFs based upon requested settings.   In practice you might only have one "class"  that implements DTF  or  you might have several but that really is an implementation that should be hidden inside locale.

I would then expect to see an implementation something like this:

LocaleInfo.prototype.dateTimeFormat(settings) {
  return new this.__internalDTFProvider(settings, this)

Now that I have written this, I see the more concise answer:

The concrete "class" that implements a specific DTF should be a private implementation detail.  It doesn't have to have a public constructor API because the constructor is called from within the  dateTimeFormat method. The instances of such private DTF constructors support the public DTF instance API.  In other words that have methods such as format.  The actual implementation of format would hang-off of the prototype object associated with such private DTF constructors.

Here is a third way to state it:

LocaleInfo is a constructor that has a public API that is used to create (or access) LocaleInfo objects.
localeInfo instances have a public API (essentially the public properties of LocaleInfo.prototype) that give access to various kinds of objects including objects that support the DTF interface
DTF objects implement the DTF public API including format
The constructor(s) for DTF objects is an implementation detail and doesn't need a public API


More information about the es-discuss mailing list