Setting condition in read-only property - OOP
Hello,
I know I am not supposed to implement conditions in get, but what if the property is read-only, like this?:
namespace practiveV9
{
internal class Program
{
static void Main(string[] args)
{
Product shirt = new Product("Shirt", 130);
}
}
internal class Product
{
private string _product;
private int _price;
private string _category;
public string Name { get; set; }
public int Price { get; set; }
public string Category
{
get
{
if (Price <= 0)
{
return $"Error";
}
else if (Price > 0 && Price < 50)
{
return $"Cheap price";
}
else if (Price >= 50 && Price < 100)
{
return $"Medium price";
}
else
{
return $"Expensive price";
}
}
}
public Product(string name, int price)
{
Name = name;
Price = price;
Console.WriteLine($"{Name}, {Price}$, {Category}");
}
}
}
Is this a good practice? Thanks.
//LE: Thanks everyone for answers.