Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
M Bryan wrote:No, this is problem logic which is implemented in several subclasses. I have to implement different techniques of encryption.
What i could do is save the name of the class in the database and do something like this:
Is this good style?
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Campbell Ritchie wrote:No.
What you are thinking of isThat is good style, but only works if you have an accessible no-arguments constructor.
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
M Bryan wrote:I just have read the wikipedia article and in the java example, there is a class and a subclass. in the upper class the method makeRoom(); is called and depending on the instanceation of the object, is it possible to call the method in the subclass.
But this does not solve my problem, because it does not show the code where it is decided which constructor shall be called.
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
M Bryan wrote:Thank you for your example.
The idea to make an extgra class for creating these object was a good idea, because now i have just one place where i have to change the code when i am adding a new connection type. Before i would have done the code you have written in the getConnector(int someID) method every time i needed a connection object.
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Yes, but the previous post had className in, so the names of the class was already available.Mohamed Sanaulla wrote:. . . just to know the name of the class, . . . just that the instance creation is done in a different way.
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|