Now let x be an instance of HelloWorld or one of its subclasses. Sends the string HelloWorld to standard out. Learning reflection allows you to get beyond this assumption and make your program do this adaptation for you. As a result, you assume that adapting code must be accomplished by a person sitting at a keyboard instead of by a program running on a computer. While these steps may be familiar to you in your role as programmer, they are not tasks that you would imagine a program doing. Change the behavior, structure, or data of the program based upon the decisions.Make decisions using the results of the examination. Examine the program for its structure or data.So mechanical, in fact, that you could write an algorithm that describes the necessary steps: Reimplementing interfaces, patching JAR files, and modifying method calls are all tedious and mechanical tasks. But they do: each one contains a change in requirements that can be satisfied only by making decisions and modifying code based upon the structure of the program. These scenarios illustrate, in turn, modularity, remote access, and security-and do not seem to have much in common. But, now legitimate users must change their calls, and unwelcome code can fake a package name. You add a parameter to each of the API calls that will hold the package name of the calling class. The public API to your module needs to accept calls only from specific packages to keep outsiders from misusing your module.Although switching is a good business decision, you now must reimplement all of your remote interfaces. After months of developing a client-side application, marketing tells you that using a different remote mechanism will increase sales.You set up some interfaces and prepare a mechanism for patching your JAR, but you know that this will not completely satisfy the need for pluggability. Your project manager is committed to a pluggable framework, knowing that the system needs to accept new components even after it is built and deployed.Without it, our solutions are messy, cumbersome, and fragile. We are often faced with problems that could be solved simply and elegantly with reflection.
0 Comments
Leave a Reply. |