Search code examples
c#design-patternspersistence

Reasons for and against objects handling their own persistence


I am looking at different options for persistence modelling in Windows Phone using Isolated Storage. One of the ideas I have come up with was the concept of each object handling its own (were it makes sense of course) persistence, rather than making a repository or other such entity for the purpose of saving objects.

I can't seem to find any good information on this method of persistence which leads me to believe I may have stumbled onto an anti pattern of sorts.

Has anyone approached persistence in this manner? If so what are your for's or against's in relation to this approach.


Solution

  • There are several undeniable truths in software development:

    1. A prototype becomes a product before you know it.
    2. An app targetted "just for platform-x" will soon be ported to platform-y.
    3. The data-store will change. Probably as a result of #2.

    There are more ( :) ) but these are enough for to answer your question:

    Go with a respository so your objects can be tested, know nothing about persistence, and you can swap out data stores (even go over the wire!) Might as well plan for that up-front.