0

我正在尝试学习 android 系统并正在研究标准(默认)DescClock 应用程序(我想我从这里得到了它:http://omapzoom.org/?p=platform/packages/apps/ DeskClock.git) . 具体来说,我的问题是关于类AlarmAlarms. Alarm是单个警报的实现,同时Alarms具有多种使用方法Alarm。的所有方法Alarms都是静态的。

现在,问题。使用静态方法创建“管理器”类是一种众所周知的设计模式吗?这种方法的一般好处是什么?谢谢!

4

1 回答 1

2

At first, I thought about this possibly being a Composite pattern, which is typical when you have a class that can be stand-alone or a container of the same type. But, when I read that all of the Alarms methods are static, I realized it has nothing to do with a Composite.

The fact that all of the Alarms methods are static implies that Alarms has no state, and only acts behaviorally on the Alarm class instances. After looking at the code, it appears as though the Alarms class is a hybrid of the Facade pattern or even a Visitor pattern, even though its only working on one class.

What the Alarms class is doing is effectively encapsulating the details of how to work on the Alarm class, thus simplifying its use for the end-user. I actually like this approach, although one could argue that if its so difficult to use the Alarm class that it has to be encapsulated like this, then maybe its design should be refactored.

于 2012-06-20T09:49:17.533 回答