Tanker indtil videre:
using System;
using System.Collections.Generic;
namespace Foobar.DomainModel
{
public abstract class Persistable
{
public bool Dirty { get; set; }
}
public class Rooster : Persistable
{
// some properties where set also sets Dirty
public List<Item> Items { get; set; }
}
public class Item : Persistable
{
// some properties where set also sets Dirty
public VCard VCard { get; set; }
public Bookmarks Bookmarks { get; set; }
public History History { get; set; }
}
public class VCard : Persistable
{
// some properties where set also sets Dirty
}
public class Bookmarks : Persistable
{
// some properties where set also sets Dirty
}
public class History : Persistable
{
// some properties where set also sets Dirty
}
}
namespace Foobar.Persist.API
{
using Foobar.DomainModel;
public interface IPersister
{
Rooster LoadAll();
void MergeUpdates(Rooster rooster);
void SaveUpdates(Rooster rooster);
}
}
namespace Foobar.Persist.Common
{
using Foobar.DomainModel;
using Foobar.Persist.API;
public abstract class PersisterBase : IPersister
{
public Rooster LoadAll()
{
Rooster rooster = LoadRooster();
rooster.Items = LoadItems(rooster);
foreach(Item itm in rooster.Items)
{
itm.VCard = LoadVCard(rooster, itm);
itm.Bookmarks = LoadBookmarks(rooster, itm);
itm.History = LoadHistory(rooster, itm);
}
return rooster;
}
public abstract Rooster LoadRooster();
public abstract List<Item> LoadItems(Rooster rooster);
public abstract VCard LoadVCard(Rooster rooster, Item itm);
public abstract Bookmarks LoadBookmarks(Rooster rooster, Item itm);
public abstract History LoadHistory(Rooster rooster, Item itm);
public void MergeUpdates(Rooster rooster)
{
// TODO
}
public void SaveUpdates(Rooster rooster)
{
foreach(Item itm in rooster.Items)
{
if(itm.VCard.Dirty)
{
SaveVCard(rooster, itm, itm.VCard);
}
if(itm.Bookmarks.Dirty)
{
SaveBookmarks(rooster, itm, itm.Bookmarks);
}
if(itm.History.Dirty)
{
SaveHistory(rooster, itm, itm.History);
}
if(itm.Dirty)
{
SaveItem(rooster, itm);
}
}
if(rooster.Dirty)
{
SaveRooster(rooster);
}
}
public abstract void SaveVCard(Rooster rooster, Item itm, VCard vcard);
public abstract void SaveHistory(Rooster rooster, Item itm, History history);
public abstract void SaveBookmarks(Rooster rooster, Item itm, Bookmarks bookmarks);
public abstract void SaveItem(Rooster rooster, Item itm);
public abstract void SaveRooster(Rooster rooster);
}
}
namespace Foobar.Persist.XML
{
// class XMLPersister that extends PersisterBase
}