Re: Localization Service



shapper wrote:
[...]
I have a table on the SQL database named Assets where I save texts
(plain, html, etc) and Files.
Each asset, whatever type is used, is saved in Binary data with a
column for Mime type.
Usually, these assets are contents to be edited by the users.

The localization system I am talking would be more specific to the
application like:
In a form I have a few labels "Name:", "Email:", etc. So I would use
this in the localization service.

Probably it would be to place this also on the Assets table and have a
column "Locked" that would allow the administrator to edit it or not
instead of having this hard coded.

[...]
What do you think?

I think as long as you don't have to go edit the code itself just to add or update language translations, that's 80% of what's important right there. The rest is implementation detail for you to decide, based on the systems you're using already.

[...]
About defining the values on the constructor I have exactly the same
problem with a validatorFactory.

I was filling the dictionary on the constructor.

From a source of data, rather than as hard-coded values in the code itself, right? (see above)

The problem is on a class I was initializing the factory outside the
methods.
Some methods would use others not.
So the validators were being added even the method didn't use them.

So maybe having the validatorFactory defined outside the methods but
adding the values to the Dictionary not on initialization but have
GetValidator to call a method Register that initializes it.

This way, I can have validatorFactory defined outside the methods and
the Dictionary filled only when GetValidator is called.

Does this make sense?

I agree that you should not initialize data structures that are not related to the code being executed. Why your validation code interacts with the localization code, I'm not sure (displaying validation errors?). But it does sound like you might need to refactor your code to avoid irrelevant dependencies.

On the other hand, beware of too much deferred initialization. If you have an opportunity to initialize a data structure you know you'll need eventually, but to do it when the user won't notice the delay, deferring initialization until the data is actually needed could be worse, causing a delay in output that could have been avoided.

I think the biggest issue is more of a design question than a functionality issue. In particular, a constructor should not take very long to execute. If you have some extensive initialization to perform, it would be better to put that in a factory method somewhere, that can either pass pre-initialized data to a private constructor, or can initialize the object after calling a private constructor.

For me, the main reason to follow this approach (but not the only) is that there's a correlation between complexity of code and time of execution. I mean, you can write a simple block of code that takes a long time to execute, but usually if your constructor takes a long time to execute it's because it's doing something much more significant than just getting the object into a coherent state.

And if it's doing that, it also is much more likely to be passing the "this" reference from the constructor to other code, which is generally a bad idea, even if passed to a private method in the class. You should do your best to avoid letting the "this" reference escape the constructor, because it can lead to uses of the object before the object's internal data structures have been completely initialized.

It's also just plain nicer to know that an object can be constructed quickly, even if there is some time-consuming initialization that still remains to be done afterwards.

Do you want me to post my code for this?

Can you fit it on a page? Honestly, broad design questions are difficult to answer in a newsgroup, because often there's way too much information to deliver and process. We all have limited time, and a question that's too complicated will often go unanswered (especially on a weekday :) ).

But if you have a concise way to describe the code and/or design, feel free to share.

Pete
.



Relevant Pages

  • Re: Message Builder vs. a Build Method?
    ... Builder class would encapsulate all the complex algorithms for making ... OTOH, as Daniel T. suggests, sometimes the initialization requires unique processing for initialization that is clearly intrinsic to the object itself. ... Constructors tend to be fragile and it is difficult to manage errors when they occur in a constructor scope, so it is usually a good idea to keep the processing in constructors as simple as possible. ... When the initialization of attribute data requires complex processing AND it seems like is intrinsic ot the object, that justifies having a separate initialization method that is invoked immediately after the constructor. ...
    (comp.object)
  • Re: Constructor as a "Reset" Button
    ... constructor is more or less just for initialization, ... In PHP you might get ... And HIPPA certification is not easy - nor is it cheap. ...
    (comp.lang.php)
  • Re: simple question
    ... I mean it will be just the same if I remove the c-tor and change this row ... member field initializers are in fact handled differently from initialization in the constructor. ... Rather, a more explicit initialization is constructed from your declarations, that looks something like the following. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Localization Service
    ... I just decided to add this "little" localization strings and phrases ... problem with a validatorFactory. ... beware of too much deferred initialization. ... private ArticleRepository _articleRepository; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Initialize an array of classes?
    ... Currently you cannot use member initialization list for a nonstatic array of a class if it does not have a default constructor. ... however you may encounter the warning C4351 and I do not think that it is useful to use such initialization for an array. ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.languages.vc)