开发者

What's the name of this java design pattern?

开发者 https://www.devze.com 2022-12-22 02:05 出处:网络
Say I have a GUI Java project of something that simulates an ATM machine, and i have classes such as :

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 t开发者_JS百科he 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

  • Model View Presenter
  • Model View ViewModel (although that seems to be specifically tied to certain Microsoft technologies)


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


Model View Controller.

0

精彩评论

暂无评论...
验证码 换一张
取 消