Synonym between files



  • There's a project from several files. In the file. A Synonyms, e.g.:

    using MyMap = Dictionary<int, string>;
    

    There is a function that uses this type as a parameter or/and reset value. Let's say,

    public MyMap foo(MyMap map) { ... }
    

    The function is declared as public It is available from the outside, i.e., including from another file. But because we're synonymous.using() may be used only within one file, such decisions shall be made:

    1. Use the file. B reference type, i.e. Dictionary<int, string>;
    2. Add a similar using file B;
    3. To refuse using and make a full class MyMap (i.e. a dip above the dictionary).

    Each approach has its advantages and minus. I'd like to know what's right to stop and why.

    Maybe it's a different task.



  • Synonym, first of all, is needed to reduce the full name of the class if you don't want to connect all the names and scream intellisense and resolve the name conflict. Sometimes synonyms are used to make a writer a specific class user comfortable.

    The less you use inheritance and composing, the more you understand your code. Everything needs to be done. Since you're referring a parameter to a fairly simple Dictionary class, it makes no sense to create a screwdriver. Call this myMap parameter and others will understand what it is.

    Inheritance, including a composite, is used only in the event of a change in the conduct of the reference class. Create new types only if you programme a new unique behaviour. And to understand the word of the parameter.

    So, in file A, create your synonym if you as a programmer are as comfortable and understandable and name this parameter as an understandable name. And in file B, just give Dictionary. But if you're more comfortable, add declaration using and file B.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2