Following is a working program to add new articles. The only thing I want is to check if there is any way to write it in a better way, or if the architecture is good as it is.
Maybe I did not have to user a new class ListOfProducts
I could easily create a list in the Articles
class and add items directly in the BuyItem()
method, but I just wanted to try inheritance and work on my skills.
Any other recommendation?
class Program
{
static void Main(string[] args)
{
Guid id;
id = Guid.NewGuid();
Articles article = new Articles(id, "This is a new article", 3, 20.2);
article.BuyItem(article);
Console.WriteLine(article);
Console.ReadLine();
}
}
public class Articles : ListOfProducts
{
private Guid Id { get; set; }
private string Description { get; set; }
private int Quantity { get; set; }
private double Price { get; set; }
public Articles(Guid id, string description, int quantity, double price)
{
this.Id = id;
this.Description = description;
//should check if the quatity > 0
this.Quantity = quantity;
this.Price = price;
}
// add item
public void BuyItem(Articles article)
{
AddNewArticle(this);
}
//Sell item
public void SellItem(Articles article)
{
RemoveNewArticle(this);
}
public override string ToString()
{
return "Article: "+ Id+" is Added.";
}
}
public class ListOfProducts
{
private List<Articles> ListOfArticles = new List<Articles>();
public void AddNewArticle(Articles art)
{
ListOfArticles.Add(art);
}
public void RemoveNewArticle(Articles art)
{
ListOfArticles.Remove(art);
}
}