views:

210

answers:

6

Hi guys,

Say I have a GUI Java project of something that simulates an ATM machine, and i have classes such as :

 - RegisterWindow
 - LoginWindow
 - MainAccountOptionsWindow

etc, where all the classes are focused around the panels/windows rather than normal OO design. Someone told me that this is a specific design pattern, maybe something starting with E, I just cant remember what they said now! Does anyone know? Is it generally bad to design stuff this way?

thanks

A: 

It looks like you're using the good old MVC pattern (Model/View/Controller), where the data computation and the data rendering are separated. The fact that the Views seem to be Swing windows here doesn't matter - it could be JSPs, or Excel extracts...

Olivier Croisier
no it does not look like that at all, it looks like he has a bunch of windows :)
willcodejavaforfood
If the xxxWindow classes contain business logic (which _seems_ to be the case) then this is definitely not MVC.
Kris
A: 

It could be part of a Model View Controller implementation.

Other related patterns are

Mark Seemann
+4  A: 

It depends on how events are propagated between to/from windows.

The nice thing with MVC is that there are so many different types of MVC that simply saying "MVC" doesn't mean very much: when talking MVC and Java a lot people actually refer to Sun's "model 2" MVC but it isn't always the case, far from it.

Your case may be a variation of HMVC/PAC but I cannot tell for sure because you only pasted names related to the view: HVMC was independently discovered by programmers unaware of the much older 'PAC' technique. PAC is a stricter subset of HMVC in that in PAC the view cannot register callbacks directly in the model (every notification must pass trough the controller, in HVMC in some case the controller can be bypassed).

200KLOC codebase where it's PAC everywhere (so a stricter subset of HMVC).

You have to know that if you are indeed using any MVC variation, it is not "bad design" for it works very well but it is certainly not "OO". In a true OO design objects know how to draw themselves and MVC is, by definition, decoupling the view from your objects, which is not OO at all. It is actually the anti-thesis of OO. There are great articles on that subject that can be found by Googling. (In short: decoupling can be a very good thing, but decoupling doesn't imply "OOness").

In addition to that, it is typically not a problem to be "not OO at all" because 99% of Java programs are not OO: they're glorified procedural programs written using a language that could be used to do OO but that usually is not.

By the way if you look on Wikipedia at the list of languages for which MVC implementation have been made you'll see that a lot of them are actually not OO languages (not even hybrid OO languages).

Webinator
upvote for "glorified procedural programs..."
Holger Kretzschmar
+1  A: 

There are many possibilities in this scenario:

  • Model-View-Controller
  • Presentation-abstraction-control
  • Model View Presenter
  • Model view viewmodel
  • Multitier architecture (often three-tier)
  • Service-oriented architecture
  • Naked objects

See this article for further info.

SDReyes
A: 

You might want to consider looking at Observer pattern, just a thought

medopal
A: 

Model View Controller.

Yuvraj Sankad