Skip to content

Instantly share code, notes, and snippets.

@explorer14
Created December 22, 2019 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save explorer14/6d0cfb5f48f31678fd7565a8acc0d6cb to your computer and use it in GitHub Desktop.
Save explorer14/6d0cfb5f48f31678fd7565a8acc0d6cb to your computer and use it in GitHub Desktop.
public class Blog
{
private readonly List<Post> posts = new List<Post>();
public string Name { get; }
public Guid Id { get; }
public IReadOnlyCollection<Post> Posts => posts.AsReadOnly();
private Blog()
{
}
public Blog(string name)
{
Name = name;
Id = Guid.NewGuid();
}
public void CreatePost(string title, string content)
{
this.posts.Add(new Post(title, content));
}
public void RemovePost(Guid postId)
{
var postToRemove = posts.FirstOrDefault(x => x.Id == postId);
if (postToRemove != null)
{
posts.Remove(postToRemove);
}
}
}
public class Post
{
public string Title { get; }
public string Content { get; }
public Guid Id { get; }
private Post()
{
}
public Post(string title, string content)
{
Id = Guid.NewGuid();
Title = title;
Content = content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment