Skip to content

Instantly share code, notes, and snippets.

@cbcwebdev
Created January 5, 2012 19:14
Show Gist options
  • Save cbcwebdev/1566724 to your computer and use it in GitHub Desktop.
Save cbcwebdev/1566724 to your computer and use it in GitHub Desktop.
public class Directory : Entity
{
protected Directory()
{
Listings = new HashedSet<DirectoryListing>();
Features = new HashedSet<IFeature>();
}
public Directory(DirectoryContext context)
{
if(context == null)
throw new ArgumentNullException("context");
Context = context;
}
public DirectoryContext Context { get; private set; }
public ICollection<DirectoryListing> Listings { get; private set; }
public ICollection<IFeature> Features { get; private set; }
public void Publish(Listing listing, DirectoryListingContext context)
{
if(listing == null)
throw new ArgumentNullException("listing");
if(context == null)
throw new ArgumentNullException("context");
var directoryListing = new DirectoryListing(this, listing, context);
if(!Listings.Contains(directoryListing))
Listings.Add(directoryListing);
}
}
public class Listing : Entity
{
protected Listing()
{
Features = new HashedSet<IFeature>();
}
public Listing(ListingContext context)
{
if(context == null)
throw new ArgumentNullException("context");
Context = context;
}
public Client Client { get; private set; }
public ListingContext Context { get; private set; }
public ICollection<IFeature> Features { get; private set; }
public void Claim(Client client)
{
if(client == null)
throw new ArgumentNullException("client");
if(Client != null)
throw new InvalidOperationException("Can't claim listing. Listing has already been claimed.");
Client = client;
}
}
The DirectoryListing class is simply a container for references to the directory, listing, and relevant context. I'd like to supplement these business rules, but am unsure as to how to approach the problem (primarily because I'm concerning myself too much with data access cascades).
If a listing is edited at the client level, all Directory Listings should inherit the changes.
If a directory listing is edited, only that Directory Listing should inherit the changes.
The purpose is to allow flexible configuration of a listing's features within a directory. I'm open to any recommendations and realize my current object model does not satisfy these rules in any way shape or form.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment