This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hey all, I have an application which needs to use two different sets of packages, based on the version of the input data. Both packages have files with same names and same function names, only the code inside the functions are different. Each package is required for parsing one version of input data. How do I do this? Thanks Rudra
You can easily avoid the need for reflection (why use it if you don't have to?) by defining an interface that defines the common characteristics that both (or all) of those classes will implement. Then once you decide which class you need to instantiate based upon your run-time criteria, you can use Class.forName().newInstance() to create the instance and assign it to a variable declared as the interface. The code referencing this variable won't care which class it's actually dealing with since they will all obey the contract of the interface. hth, bear
Hi Bear, Thanks for the reply. Both the packages I am referring to, have more than 40 classes in each of them & they are generated by an automated tool based on the format of the user data. The latest version of data has more functionality, hence more classes are there with more functions than the old classes. So, these packages have some classes in common with some functions inside them common(not the whole class is common). How do i go about dealing with this? Thanks Rudra.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Rudra, regardless of the scale, the general solution to the problem of having multiple classes represent the same set of functionality is through the uses of interfaces. Taking Ilja's advice on researching creation patterns would be a great thing for you to do as you might find descriptions of solutions that match the needs of your project. hth, bear