Hello, I have noticed two patterns, heavily used in this forum - Factory and MVC. Do we really need them? 1. Factory pattern. Consider following architecture: Business interface with methods like book() and search() is implemented as local(for alone mode) and remote(for cleint mode) objects. Is it worth to have 4 classes(BusinessFactory interface and 3 implementations for each mode) instead of 3 static initializers? In either case we need to check for input argument(mode) and either call static initializer or instantiate appropriate factory. And what do we win from the latter approach? Instead of passing Business instance to GUI(or whatever) constructor, we pass factory isntance. 2. MVC pattern. IMO we need to implement it for main GUI since it is indirectly required by Sun. But how about those connection dialogs(host, port) - do we really need MVC for them? Take a look at JFileChooser - it has no MVC and it's ok, since it is too simple. Conclusion: IMO design pattern is only a tool to build smth, not a goal itself.
Hi Gytis, I agree that design patterns are a tool which may be used, not a requirement. There will be times when you will look at a problem and the obvious solution will use a particular pattern. There are other times when the solution is similar to a particular pattern but requires slight modifications (look at how many variations of MVC exist). And there are times when forcing usage of a pattern will add complexity, confuse the issues, and gain nothing. Using design patterns can help with how you think about a problem, how you explain it to someone else, and how easy it is for someone else to maintain (or mark) your code. But if the pattern does not meet your requirements, don't try and force it. Regards, Andrew
I agree with Andrew about not forcing a solution around a pattern. Patterns, used correctly, are not heavyweight and the MVC pattern is used within the JTable as the default structure. Not using the MVC pattern in the JTable would mean that you have created your own table structure rather than reusing the Sun API. MVC is a very diverse pattern in that it is used as an architecture level pattern and application level pattern. How and where you use it (if at all) depends upon your solution. So long as you have detailed your decisions extensively in your documentation and have good reasons why you have diverted away from the MVC, which was a requirement in my assignment, Sun should judge it fairly. However, your reasons will have to be very good as the MVC is the standard Sun approach to architecturally solutions. Good luck.