Platinum Partner
java,reflection

About Reflection…

I never thought that will be faced with the need to write code that analyzes itself, but recently it happened. It should be noted that many developers do not use this method under any circumstances ... But it turned out that this code is incredibly flexible. Why?

Writing such a code has led me to release the following features:

  1. Self-analysis enables you to create multiple configurations at the level of code that makes the system flexible and modular.
  2. Having defined the interface (I do not mean Java interfaces) of the analyzed classes, you do not need to make any (!) changes in the code. Maybe you just you want to use annotations, which still remains a very flexible solution. ;)
  3. We get the independence of code from the existence and correctness of CDI. Of course, if you have correctly written the analyzing code...
  4. The code's logic cuts a lot of extra code that validates the use of dependency.
  5. And the most attractive, that it becomes possible to create a common interface to exchange parameters! You no longer need to think and worry about the number of parameters in the called method, you simply create a special object, the properties of which method will be determined.

The advantages are very attractive to me, but maybe they are insignificant for other developers because of the obvious problems:

  1. It is very difficult to determine the rules of the code analysis in the project. 
  2. It is difficult to unify these rules for the allocation of the universal functionality.
  3. Exchanging interface parameters is not always possible to unify even in any one module in the project without unnecessary complications in the architecture.

Solving these problems may leads to a very convenient framework, some of the makings of a functional already exist in specialized libraries (Spring Forms, Hibernate).

With all the charms that I found for myself in such an approach, you should be extremely careful with the performance ... Self-examination greatly slows down the system, so the use of reflection is necessary only when the gains from such an analysis (eg, cutting off unnecessary computations) will be significantly greater than the losses from the introspection.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}