Answer the question
In order to leave comments, you need to log in
Can this solution be used instead of annotations?
In this article, the use of the annotation is analyzed: the user enters a command and arguments, and the program executes it.
Will the following solution converge in performance and usability:
Create a static class in which to store the dictionary: {command : function reference}. Then, when receiving the command and arguments, call the function with the passing of arguments?
Answer the question
In order to leave comments, you need to log in
No problem! I often do just that. Reflection is still used, both in annotations and when constructing directly.
For annotations - you can annotate anything, even a class, even a parameter, even a function.
Without annotation - you need to adhere to some kind of interface, especially if the functions are classes, otherwise everything is the same.
PS. Actually, at the end of the article, almost the same thing is indicated
It is absolutely indisputable that this problem can be solved in many other ways. Yes, everything that can be done with the help of annotations / reflections can be done without them, the only question is convenience, optimality and code size, of course, sticking an Annotation wherever there is the slightest hint that it will be possible to use it is also not the most rational option , in everything you need to know the measure =). But when writing APIs, Libraries or programs in which it is possible to repeat the same type (but not quite the same) code, annotations are undoubtedly the best solution.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question