• Post Reply Bookmark Topic Watch Topic
  • New Topic

Factory & Singleton Design Patterns: Building a Simple Form  RSS feed

 
Dan Pants
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy ranchers! I posted a question about this a few days ago, but since I marked it as resolved prematurely I thought I might repost it. Here is the link to the previous post.

As I mentioned in the previous post, my assignment was to create a simple form that demonstrates the use of the factory and singleton design patterns. "Use the Factory pattern to ensure that each form input consists of a text label and a textfield. Use the Singleton pattern for the submit button."

I have been struggling with a this a bit, but I rewrote the program following the example I had much closer, and I'm hoping someone can tell me if I'm on the right track at least.

Here's what I have:

Form.java file



Name.java file (I have a similar files just like this for Address.java, City.java, State.java, Zip.java and Phone.java)



FormFactory.java file



SubmitButton.java file (I think I'm having the most trouble with this one)



FormFactoryDemo.java file



I am still working on it, but any hints or guidance would be much appreciated. It compiles at the moment but I get a null pointer exception in the main method of the FormFactoryDemo file.

Can anyone tell me if I am on the right track at least? Thanks to all for your input and advice in advance!


 
Jacob Anawalt
Ranch Hand
Posts: 64
Linux Netbeans IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When I first started reading your post I thought the Factory would create some kind of JComponent that would be a form field and label, so when I got to public void getFormField () I was confused by it returning void. (When I see getSomething, I expect it to return Something.)

Then I read the getFormField implementation in Name and saw it was using a Scanner on System.in, I did a double take because I thought this was suppose to be a graphical and not a command line interface program.

FormFactory's getForm is a factory pattern, but I wonder if you meant to use equalsIgnoreCase based on the way you call it in FormFactoryDemo.java.

Does the program work the way you expect it to? Does it work the way your instructor expects it to? If so, I'll need to reset my expectations of using a factory pattern to create input forms that consist of a text label and an input field. If not, you may not be on the right path yet.

 
Dan Pants
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Jacob Thanks for your input! If you saw my previous post, I first created a GUI program with the JFrame, but completely changed the program to fit the factory pattern and I must have followed the example I had too closely. And indeed the getFormField() methods should be something more like build or add form field. I guess I have some more work to do.

Thank you for the notes and advice!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!