简体   繁体   中英

What's the name of this java design pattern?

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

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).

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.

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...

It could be part of a Model View Controller implementation.

Other related patterns are

您可能需要考虑观察者模式 ,只是一个想法

模型视图控制器。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM