views:

58

answers:

4

Hello guys,

What do you think about the use of public static classes to hold on errorMessages and Ui button names, etc?

Example:

   public static class UiMessages
    {
        public const string ConfirmationDialogTitle = "Atenção";
        public const string ConfirmationLandOwnerDelete = "Você tem certeza que deseja deletar os proprietários selecionados?";
        public const string ConfirmationProfessionalDelete = "Você tem certeza que deseja deletar os profissionais selecionados?";
        public const string ConfirmationGnssDevice = "Você tem certeza que deseja deletar os aparelhos selecionados?";
    }

Is this a bad pratice? Is there a better way to handle this?

+1  A: 

It's jut another way of defining global variables, and is just as good/bad as any other global variables.

Do these really need to be globally accessible? It would seem that each would only be needed in one class.

The only advance I can see is that you have all the string available in one place if you wanted to translate them into a different language, but that brings us into a whole different area.

James Curran
Yea that's kinda the idea. But since they are constants, I don't think I'll have problems of external apps accessing my class. As far as I'm concerned, there are groups of strings that will be open for each part of the software - so I might do something about that. Any other opinions?
George
+1  A: 

Hi! This should be of help:

http://www.c-sharpcorner.com/uploadfile/ankithakur/globalization_localization_in_dotnet_csharp07032006023510am/globalization_localization_in_dotnet_csharp.aspx

(Whoops, that's for ASP.NET).. try this:

http://msdn.microsoft.com/en-us/goglobal/bb688096.aspx

And a good example here:

http://msdn.microsoft.com/en-us/library/y99d1cd3(VS.71).aspx

.NET has localization and globalization support throughout, intended for just this kind of thing.

Hope that helps!

Kieren Johnstone
I'll look it up. Thanks for the support.
George
+2  A: 

In this case, I would say yes, it is bad practice -- because you likely want internationalization and localization expansion; you may be able to much better utilize properties or resources for such a task.

However, I use similar classes for internal-only (e.g. not displayed to the user) data such as names of data-columns.

pst
I have a bunch of data-columns too. I might go to a mixed approach between resources and constant classes.
George
+2  A: 

In C#, use .resx files and make use of the built-in localization functions.

Michael Stum