• Post Reply Bookmark Topic Watch Topic
  • New Topic

Factory pattern problem

 
Georgios Chatziefstratiou
Ranch Hand
Posts: 106
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello i am trying example with factory pattern but i get an error. This is my code if anyone can help


the error is



and the code is








Why do i get such a message ?I have try the args[] array but it will not change.what can i do?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Horche. Welcome to the Ranch!

Anyway, I assume Factory.java line 29 corresponds to line 12 in that listing? In that case, the problem is that the argument array doesn't have two entries. Maybe you should print out the array to check what it does actually contain. How are you executing the program?
 
Mohamed Sanaulla
Bartender
Posts: 3168
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Horche Gratsias wrote:
Why do i get such a message ?I have try the args[] array but it will not change.what can i do?

String[] args is equivalent to String args[].
As Matthew pointed out the possible erroneous line, I think you are using an IDE to run the program and you need to setup the IDE to accept command line arguments.
 
rajareddy dodda
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes as mentioned above how the parameters passed to the program, look into that will make more clear .
 
Georgios Chatziefstratiou
Ranch Hand
Posts: 106
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply
 
Junilu Lacar
Marshal
Posts: 10410
125
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to take a look at http://www.oodesign.com/factory-pattern.html to pick up some tips on a better implementation. As you'll see, your current implementation is what the article calls a "noob implementation" and violates what is called the "Open-Closed Principle" of object-oriented design.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!