Over a million developers have joined DZone.

About Reflection…

· Java Zone

Learn more about the advantages of moving from a monolithic to microservices architecture.  Brought to you in partnership with IBM.

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.

From Idea to Application gives you the architecture to quickly build, manage and run a range of applications (web, mobile, big data, new smart devices, etc.) on an open-standard, cloud-based platform. See why developers are using IBM Bluemix. Brought to you in partnership with IBM.


The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}