0

I am building a pair of components that communicates in a one-way fashion:

[ JButton ] --> data...process...process...out --> [ JTextField ]

The JButton allows the user to select a file and the JButton's ActionListener picks up the click and pulls out the file name and directory. I then need that information to be displayed by the JTextField. Such functionality is so basic, it need not ever change. Someone suggested a way to relay the message here, but I am asking another question: should I skip the MVC?

[ JButton ]  --> [ JTextField ]

Simple is best, right? That's the simplest and clearest way I can think of of relaying the message. I mean, just modify the the JTextField by JButton's ActionListener. So should I go with this simpler approach or try to apply MVC anyway?

  • I think you're trying to compare chalk and cheese. They can both be white, but that's kinda where the similarity ends. – Robert Harvey Mar 28 '14 at 22:58
0

It's ok to drop MVC if you're looking to write the fewest lines of code possible.

If that's your goal, you may also be interested in minimizing the number of objects you have instantiated at any one time.

You could achieve this by getting rid of your JTextField. Simply customize your JButton to also display a text field and voila! One object does two things.

Feels like a victory right? No?

But it technically works, and it's pretty simple. So it must be the best, no?

Probably not.

OK, so my example was a bit extreme, but I was simply trying to challenge your notion of "Simple is best".

The whole point of using a pattern like MVC isn't to produce simple code in terms of fewest classes, fewest objects, or fewest lines of code. It's about producing code that is simple to maintain.

Eventually, ease of maintainability will become a big concern in your project. Even if you don't think it will and even if you think your code will never change.

So, my suggestion: Take the initial hit of writing more code. Apply MVC. You'll get more loosely coupled code which will make debugging and maintaining so much easier.

In Summary

Simple may be best, but it really depends on which definition of simple you're striving for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.