Пример #1
0
        public void Run()
        {
            PostDatabase  db       = new PostDatabase();
            List <string> newPosts = new List <string>();

            newPosts.Add("original post");
            newPosts.Add("#tag post");
            newPosts.Add("@mention post");
            newPosts.Add("http post");

            Post postObj;

            foreach (string post in newPosts)
            {
                if (post.StartsWith("#"))
                {
                    postObj = new TagPost();
                }
                else if (post.StartsWith("@"))
                {
                    postObj = new MentionPost();
                }
                else if (post.StartsWith("http"))
                {
                    postObj = new LinkPost();
                }
                else
                {
                    postObj = new Post();
                }

                // The issue here is that the create post will implement the code on Post but not other!
                string result = postObj.CreatePost(db, post);
                Console.WriteLine(result);
            }
        }
Пример #2
0
 public virtual string CreatePost(PostDatabase db, string post)
 {
     return(db.Add(post));
 }
Пример #3
0
 public override string CreatePost(PostDatabase db, string post)
 {
     return(db.AddLink(post));
 }