Creational Patterns
Redesign Home Design Patterns Coding Idioms Classes
Creational

Structural

Behavioral

Design patterns can be thought of as software architectural features that solve particular engineering problems. The standard work on the subject, Design Patterns (Gamma, Helm, Johnson & Vlissides —sometimes referred to as the Gang of Four— 1994) lists 23 separate patterns divided into Creational, Structural and Behavioral patterns. XSPEC12 uses about ten of them. We describe briefly below what specific use each pattern has  and the issue within XSPEC12 that it addresses. We follow the definition of a pattern given in Gamma et al. with concrete examples from our code.

  • Creational Patterns (issues in creating objects)

      Singleton:

        Ensure a class only has one instance, and provide a global point of access to it.

        Singleton is used in various places throughout the code: to ensure that global containers holding data required for multiple commands is available everywhere and references to them uniquely defined. The Fit and Plot objects are also Singletons, as is a registry maintaining Parameter links.

      Factory:

        Define an interface for creating an object, but let subclasses decide which class to instantiate.

        Factory, sometimes called "virtual constructor," constructs different members of a class hierarchy according to different inputs. It is used in XSPEC12 to return different kinds of model components (Additive, Multiplicative etc) according to a parameter. The Component subtypes differ from each other in the way they are calculated and combined with other components. In CCfits, Factory is implemented in a completely different way (using templates) to return Image, Column and Keyword objects depending on what type the programmer implicitly requests in their code.

      Abstract Factory:

        Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

        Abstract Factory is used to create simultaneously a set of objects such as a DataSet, Response, Background, etc that are designed to work together. It works hand in hand with the Prototype pattern to allow the program to decide what set of objects to make when the user requests the reading of a particular data file.

      Prototype:

        Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.

        In the prototype pattern, we register a Prototype object that consists of a set of empty DataSet, Response, Background and Correction class instances. A file entered by the user can be tested for its contents against the available prototypes, and the Abstract Factory then returns the appropriate set of classes to be filled by data from the file entered. New file formats can be added to XSPEC12 at runtime by registering a new prototype against which to check data files.



[Redesign Home]
[Design]
[Problem]
[Scripting]
[Compatibility]

Xspec Xspec Home Page


HEASARC Home | Observatories | Archive | Calibration | Software | Tools | Students/Teachers/Public

Last modified: Wednesday, 02-Mar-2011 11:23:42 EST