Created
January 5, 2012 19:14
-
-
Save cbcwebdev/1566724 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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