Encapsulate mutable collections in Bin and Result

Replace public mutable collection fields/properties with private
backing fields and expose them as IReadOnlyList. Add proper methods
for mutation (AddItem, AddItems, RemoveItem, SortItems).

Changes:
- Bin.Items: Now private with AddItem/AddItems/RemoveItem/SortItems
- Result.ItemsNotUsed: Now readonly with Add methods
- Result.Bins: Now readonly with Add methods
- Updated all engine classes to use new encapsulated APIs

This improves encapsulation and prevents external code from
bypassing business logic by directly manipulating collections.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
AJ
2025-11-18 16:02:48 -05:00
parent 2c6fe924e5
commit 703efd528a
5 changed files with 80 additions and 33 deletions

View File

@@ -7,14 +7,36 @@ namespace SawCut
{
public class Bin
{
public List<BinItem> Items;
private readonly List<BinItem> _items;
public Bin(double length)
{
Items = new List<BinItem>();
_items = new List<BinItem>();
Length = length;
}
public IReadOnlyList<BinItem> Items => _items;
public void AddItem(BinItem item)
{
_items.Add(item);
}
public void AddItems(IEnumerable<BinItem> items)
{
_items.AddRange(items);
}
public void RemoveItem(BinItem item)
{
_items.Remove(item);
}
public void SortItems(Comparison<BinItem> comparison)
{
_items.Sort(comparison);
}
public double Spacing { get; set; }
public double Length { get; set; }