简体   繁体   English

这个Java设计模式的名称是什么?

[英]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 : 说我有一个模拟ATM机器的GUI Java项目,并且我有一些类,例如:

 - RegisterWindow
 - LoginWindow
 - MainAccountOptionsWindow

etc, where all the classes are focused around the panels/windows rather than normal OO design. 等等,其中所有课程都围绕面板/窗口而不是普通的OO设计。 Someone told me that this is a specific design pattern, maybe something starting with E, I just cant remember what they said now! 有人告诉我这是一个特定的设计模式,也许是以E开头的东西,我只是不记得他们现在说的是什么! 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. 使用MVC的好处是,有太多不同类型的MVC,只是说“ MVC”并没有多大意义:在谈论MVC和Java时,很多人实际上是指Sun的“模型2” MVC,但事实并非如此。总是这样,远非如此。

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. 您的情况可能是HMVC / PAC的变体,但我不能确定,因为您仅粘贴了与视图相关的名称:HVMC是由程序员独立发现的,不知道更老的“ PAC”技术。 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). PAC是HMVC的一个更严格的子集,因为在PAC中,视图无法直接在模型中注册回调(每个通知都必须通过控制器,在HVMC中有时可以绕过控制器)。

200KLOC codebase where it's PAC everywhere (so a stricter subset of HMVC). 200KLOC代码库在任何地方都是PAC(因此是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". 您必须知道,如果您确实在使用任何MVC变体,它并不是“糟糕的设计”,因为它可以很好地工作,但肯定不是“ 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. 在真正的OO设计中,对象知道如何绘制自己,而MVC定义上就是将视图与对象分离,而这根本不是OO。 It is actually the anti-thesis of OO. 它实际上是面向对象的对立面。 There are great articles on that subject that can be found by Googling. Googling可以找到有关该主题的出色文章。 (In short: decoupling can be a very good thing, but decoupling doesn't imply "OOness"). (总之:去耦可能是一件非常好的事情,但是去耦并不意味着“ 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. 除此之外,“根本不是OO”通常不是问题,因为99%的Java程序都不是OO:它们是美化的过程程序,使用的语言可以用来进行OO,但是通常不。

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). 顺便说一句,如果您在Wikipedia上查看已实现MVC的语言列表,您会发现其中许多实际上不是OO语言(甚至不是混合OO语言)。

There are many possibilities in this scenario: 在这种情况下,有很多可能性:

  • Model-View-Controller 模型 - 视图 - 控制器
  • Presentation-abstraction-control 演示抽象控制
  • Model View Presenter 模型视图演示者
  • Model view viewmodel 模型视图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. 看来您使用的是旧的MVC模式(模型/视图/控制器),其中数据计算和数据呈现是分开的。 The fact that the Views seem to be Swing windows here doesn't matter - it could be JSPs, or Excel extracts... 视图在这里似乎是Swing窗口这一事实并不重要-它可能是JSP或Excel提取...

It could be part of a Model View Controller implementation. 它可能是模型视图控制器实现的一部分。

Other related patterns are 其他相关模式是

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

模型视图控制器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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