Should I adhere to the terminology of project templates?

When I implement design patterns, should I store terms such as “strategy”, “visitor”, “facade”, or can I customize these names in the context of my application? What is the best practice?

+4
source share
4 answers

I think that you should always adhere to some reference to the pattern in its name, where it makes it meaningful and descriptive.

Templates are a means of communication. If I find code that is XyzVisitor, I know that the visitor pattern has been used. With nothing else, the name passed a whole stack of information about how the code works (or should work).

However, sometimes it would be a little strange. For instance. DatabaseSingleton. While AccountRefreshCommand fits pretty well.

+3
source

You must match these names in the context of the application. This will make it easier for people to read your code. You can add templates to your documentation.

+5
source

Depends on which template you are using. Some template names may be mixed with class names, for example. I use

class LogFactory class StudentsAdapter 

for factory and adapter templates, but

 Engine.Instance 

for singleton.

+1
source

Depending on whether you are happy to rename the class if you use a different template, for me this will cause too many problems with Hungarian notes.

+1
source

Source: https://habr.com/ru/post/1479548/


All Articles