using System; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; 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 { #region Private Attributes /// /// 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; #endregion #region Public Properties /// /// A short description of the Item. Useful to know what this Item stand for. /// public string Description { get; set; } #endregion #region Constructors protected BaseItem(uint id, string description="Any Item.") { Id = id; Description = description; } #endregion #region Public Methods public override string ToString() { return $"[ Class -BaseItem- ]\n\n" + $"\t.Id - {Id}\n" + $"\t.Description - {Description}\n" + $"______\n\n"; } #region IDisplayable Implementation public void DisplayId() { Console.WriteLine($".Id - {Id}"); } public void DisplayDescription() { Console.WriteLine($".Description - {Description}"); } public void DisplayItem() { Console.WriteLine(this.ToString()); } #endregion #region IEquatable implementation public int GetHashCode([DisallowNull] BaseItem obj) { return obj.Id.GetHashCode() + obj.Description.GetHashCode(); } public bool Equals(BaseItem? other) { if (other == null) return false; return (this.Id == other.Id) && (this.Description == other.Description); } #endregion #endregion } }