One Into Many

From CSSEMediaWiki
Revision as of 06:23, 10 August 2009 by Matthew Harward (Talk | contribs)
Jump to: navigation, search

Contents

Overview

This pattern is to be used in cases where a previous implementation has a one to one relationship and it needs to be modified to a one to many relationship. This pattern is specifically designed for Objects; however it may be used for lower or higher level concepts.

The Problem

During initial coding/design, you failed to notice that a relationship had the potential to be one-to-many and instead coded it as one-to-one. Now, you realise your problem and need to rectify it.

General Issues

Solution

  1. If the class/object implements a Singleton pattern, remove the code required to save a single instance.
  2. If it is a simple case of an object only being held by another object once when multiple are required, use a collection like a Set or List to encapsulate these objects.
    1. Refactor to change any existing getter/setter methods if required.
  3. If a more complex problem exists, follow these steps:
    1. ...

See Also

Personal tools