using System;
using System.ComponentModel;
namespace Model
{
///
/// Define the base structure of any Items.
/// An Item can be identifed and have a short description. It can also be displayed.
///
public abstract class BaseItem : IDisplayable, IEquatable
{
///
/// The identifier of an Item.
/// The first number correspond to the typs of the Item.
///
virtual public uint Id
{
get => _id;
init => _id = value;
}
protected uint _id;
///
/// A short description of the Item. Useful to know what this Item stand for.
///
public string Description { get; set; }
protected BaseItem(uint id, string description="Any Item.")
{
Id = id; Description = description;
}
public override string ToString()
{
return
$"[ Class -BaseItem- ]\n\n" +
$"\t.Id - {Id}\n" +
$"\t.Description - {Description}\n" +
$"______\n\n";
}
// IDisplayable Implementation
public void DisplayId()
{
Console.WriteLine($".Id - {Id}");
}
public void DisplayDescription()
{
Console.WriteLine($".Description - {Description}");
}
public void DisplayItem()
{
Console.WriteLine(this.ToString());
}
// IEquatable implementation
public bool Equals(BaseItem? other)
{
if (other != null)
return this.Id.Equals(other.Id);
return false;
}
public override bool Equals(object? obj)
{
BaseItem? baseItem = obj as BaseItem;
if (baseItem == null) return false;
if (baseItem == this) return true;
return this.Id.Equals(baseItem.Id);
}
public override int GetHashCode()
{
return this.Id.GetHashCode();
}
}
}