Revision c79537a...

Go back to digest for 22nd July 2012

Other in KDE Base

Erlend Hamberg committed changes in [kate] /:

Use Singleton pattern for commands

Add a static self() method to KateCommands::CoreCommands,
KateCommands::ViCommands, KateCommands::AppCommands,
KateCommands::Character, KateCommands::Date and KateAppCommands.
This allows for easier code reuse among commands. The Singleton
pattern is justified as follows:

1. The Command classes have no state, and the only reason they
are instantiated at all is so they can be passed to the command
system. Therefore, they only need to be instantiated once.
2. Other parts of Kate already provide static access: e.g., the
KateDocManager, KatePluginManager and KateGlobal classes all
have a self() method. So there is some precedent for making
common components easier to access.
3. While the Singleton pattern can turn into an anti-pattern if
different parts of the code modify the object as they would a
global variable, the Command objects are stateless and immutable.
In this regard, they are similar to a constant defined in a
much-included header file.

The Singleton pattern guarantees that only one instance of the class
is ever created, and provides access to this instance with the static
self() method.

File Changes

Modified 8 files
  •   kate/app/kateapp.cpp
  •   kate/app/kateappcommands.cpp
  •   kate/app/kateappcommands.h
  •   part/script/katescriptmanager.cpp
  •   part/script/katescriptmanager.h
  •   part/utils/katecmds.cpp
  •   part/utils/katecmds.h
  •   part/utils/kateglobal.cpp
8 files changed in total