-
-
Save explorer14/6d0cfb5f48f31678fd7565a8acc0d6cb 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 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