Static or Resource Class?

1

I want to abstract the frequently used phrases / words in my project, however, I have doubts where to put them Static Class or create a Resource ? What is the recommendation of best practices and performance?

Note: This project will not be multilingual.

Ex:

public Static class Mensagem
    {
        public const string Ok = "OK";
        public const string Cancelar = "Cancelar";
    }

Ex:

<data name="OK" xml:space="preserve">
    <value>OK</value>
</data>
<data name="CANCELAR" xml:space="preserve">
    <value>Cancelar</value>
</data>
    
asked by anonymous 10.05.2015 / 20:39

1 answer

2

If it is your wish that these phrases / words can be changed at some point, use Resource . It is the resource that has been made for this, and the design pattern has several features that may be interesting in refactoring, so it can be considered the best practice for your case. In this answer I approach these functionalities from the point of view of multiple languages , but can perfectly fit your project.

Now, if these are just recurring messages, I see no problem using static class . The function fulfilled will be the same, although the approach is a bit more homely.

In performance the difference is imperceptible, since the Resource file is a key-value (thus indexed) dictionary, and the static class is compiled.

    
10.05.2015 / 20:50