【发布时间】:2021-03-08 21:25:08
【问题描述】:
我正在开发一个 EquipmentManager 类,该类需要能够查看所有 ShortTrailers、LongTrailers 和 Tractors,基于唯一 ID 添加新的拖拉机/拖车,并删除拖拉机/拖车基于其 ID。
我不确定从哪里开始。我目前的困境是尝试在EquipmentManager 类中仅列出Trailer,该类可以结合ShortTrailer 和LongTrailer 的两个类。
EquipmentManager 类:
using System.Collections.Generic;
namespace BusinessLayer
{
public class EquipmentManager
{
private List<Tractor> Tractors {get; set;}
private List<ShortTrailer, LongTrailer> Trailers {get; set;}
// Incorrect but the idea^
public EquipmentManager() //constructor
{
Trailers = new List<Trailer>();
Tractors = new List<Tractor>();
}
public object GetTractorCount()
{
int TractorCount = 0;
return TractorCount;
}
public object GetTrailerCount()
{
int TrailerCount = 0;
return TrailerCount
}
public string ViewTractors(Tractors)
{
new List<Tractors> = " ";
return Tractors;
}
public string ViewTrailers()
{
new string List<Trailers>;
return Tractors;
}
public bool AddTractor()
{
}
public bool RemoveTractor()
{
}
public bool AddTrailer()
{
}
public bool RemoveTrailer()
{
}
}
}
Tractor、ShortTrailer 和 LongTrailer 的类分别在它们自己的 .cs 文件中:
namespace BusinessLayer
{
public class Tractor
{
string ID;
int[] Terminal = {01, 02, 03};
string[] Status = {"Arrived", "Fueled", "Serviced", "Ready"};
}
public class ShortTrailer
{
string ID;
int[] Terminal = {01, 02, 03, 04, 05, 06, 07, 08, 09, 10};
string[] Status = {"Arrived", "Fueled", "Serviced", "Ready"};
int Length;
int Width;
int Height;
}
public class LongTrailer
{
string ID;
int[] Terminal = {01, 02, 03, 04, 05, 06, 07, 08, 09, 10};
string[] Status = {"Arrived", "Fueled", "Serviced", "Ready"};
int Length;
int Width;
int Height;
}
}
【问题讨论】:
-
这似乎是在乞求
ITrailer接口 -
这是用于课堂项目还是用于工作?我问的原因是答案会根据用例的不同而有所不同。简而言之,您正在混合模型和逻辑。你的
Manager不应该有模型。它应该在模型类上运行。如果这是为了学校,使用Dictionary将内容存储在内存中是相当简单的。如果没有,对于实现,您需要有类来将模型状态值保存在数据库中,例如DynamoDb等。 -
短拖车和长拖车有什么区别?为什么他们需要有自己的课程?
-
@ColmPrunty 或者说实话
IEntity。 -
@seasharp 用一个基本示例更新了我的答案,以帮助澄清我指出的一些项目。祝你好运!
标签: c# list inheritance overloading