Re: Localization Service
- From: Peter Duniho <no.peted.spam@xxxxxxxxxxxxxxxxxx>
- Date: Mon, 07 Dec 2009 10:26:08 -0800
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
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
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.
- Re: Localization Service
- From: shapper
- Re: Localization Service
- Prev by Date: Re: C# registry read converts string
- Next by Date: Re: Graphics.DrawString character set problem
- Previous by thread: Re: Localization Service
- Next by thread: Re: Localization Service