현재 "도메인 기반 디자인"을 배우기 위해 노력하고 있습니다.도메인 기반 디자인 학습 및 연습, 일부 지침 찾기
누군가 어떻게 이러한 엔티티를 디자인 할 것인지 궁금합니다. 문제가있는 도메인의 영역을 강조하기 위해 "실제"응용 프로그램을 설명하는 데 오랜 시간이 걸릴 것이므로 객체 모델을 단순화했습니다.
따라서 CustomerInfo 집합에는 항목 목록이 들어 있습니다. 디자인에 문제가있는 것은이 "엔트리"객체입니다.
//Lets call the CustomerInfo the Aggregate Root
public class CustomerInfo {
/* Other properties removed, to simplify question */
public List<Entry> Entries { get; set; }
}
항목 개체는 몇 가지 다른 엔터티 목록으로 설명 될 수 있습니다. 여기에주의해야 할 것은 "Entry"가 "오직"이 목록 중 하나에 의해 설명 될 수 있다는 것입니다. 내 도메인에서는 항목에 위젯 목록과 ThisThings 목록이있는 것은 이해가되지 않습니다.
복잡합니다. 엔티티 악세사리, ThatThing, ThisThing 및 TheOtherThing 모두 같은 특성을 가지고 있지만,이 도메인의 맥락에서 그 의미가 매우 다르다.
이것은 현재 도메인 모델입니다. 어느 내가 제대로이 "항목"엔티티를 모델링하는 방법이다와 사투를 벌인거야 어떤 사용자
public class Entry
{
public Guid EntryId { get; set; }
/* Other properties removed, to simplify question */
public List<Widget> Widget { get; set; }
public List<Trinket> Trinkets { get; set; }
public List<ThatThing> ThatThings { get; set; }
public List<ThisThing> ThisThings { get; set; }
public List<TheOtherThing> TheOtherThings { get; set; }
}
public class Widget
{
public Guid Widgetid { get; private set; }
public string Name { get; private set; }
public int Size { get; set; }
public string Color { get; set; }
}
public class Trinket
{
public Guid Trinketid { get; private set; }
public decimal Cost { get; private set; }
public Construction Construction { get; private set; }
}
public class ThatThing
{
public Guid ThatThingid { get; private set; }
public decimal Cost { get; private set; }
public Construction Construction { get; private set; }
}
public class ThisThing
{
public Guid ThisThingid { get; private set; }
public decimal Cost { get; private set; }
public Construction Construction { get; private set; }
}
public class TheOtherThing
{
public Guid TheOtherThingId { get; private set; }
public string Name { get; private set; }
public Construction Construction { get; private set; }
}
public class Construction : ValueObject<Construction>
{
public int Size { get; private set; }
public string Weight { get; private set; }
public string Unit { get; private set; }
public string Form { get; private set; }
}
만 목록 중 하나가 채워져 있는지 확인하기 위해 모든 검증을 가지고 내가 좋아하지 않는다.
1) 설계대로 유지하고이 미친 검증에 의존해야합니다.
2)이를 처리하기 위해 다형성 모델을 작성해야합니까?
public interface IWidget{
public Guid Widgetid { get; set; }
}
public interface IDifferentWidget:IWidget
{
public decimal Cost { get; set; }
public Construction Construction { get; set; }
}
public class Widget:IWidget
{
public Guid WidgetId { get; private set; }
public string Name { get; private set; }
public int Size { get; set; }
public string Color { get; set; }
}
public class Trinket : IDifferentWidget
{
public Guid WidgetId { get; private set; }
public decimal Cost { get; private set; }
public Construction Construction { get; private set; }
}
public class ThatThing : IDifferentWidget
{
public Guid WidgetId { get; private set; }
public decimal Cost { get; private set; }
public Construction Construction { get; private set; }
}
public class ThisThing : IDifferentWidget
{
public Guid WidgetId { get; private set; }
public decimal Cost { get; private set; }
public Construction Construction { get; private set; }
}
public class TheOtherThing : IDifferentWidget
{
public Guid WidgetId { get; private set; }
public decimal Cost { get; private set; }
public Construction Construction { get; private set; }
}
그런 다음 항목 개체는 같을 것이다, 그러나
ThisThing 및
ThatThing이 같은 항목 목록에 추가되는 것을 방지하지 않습니다.
public class Entry
{
public Guid EntryId { get; set; }
/* Other properties removed, to simplify question */
public List<IWidget> Widgets { get; set; }
}
3) 내가 완전히 WidgetEntry 같은 다른 항목 개체를 만들 경우, 집계 루트 때문에 공통 인터페이스와 ThisThingEntry 지금과 같습니다
//Lets call the CustomerInfo the Aggregate Root
public class CustomerInfo {
/* Other properties removed, to simplify question */
public List<IEntry> Entries { get; set; }
}
를 내가의를 고려 한 다른 옵션을 고려 이 도메인 제한을 다루는 유일한 해결책 "항목"은 "목록"중 하나에 의해 설명 될 수 있습니다.은 # 3입니다.
모든 지침을 매우 높이 평가하며, estion!
/******************************* REVISED DOMAIN 디자인 *********** ************/
나는 여전히 내 도메인에 사용자가에 추가하는 다양한 항목에 의해 CustomerInfo을 설명하는 의미가 있습니다 때문에 CustomerInfo가 집계 될 것으로 판단 "CustomerInfo"엔티티를 빌드하십시오.
//Lets call the CustomerInfo the Aggregate Root
public class CustomerInfo {
public Guid CustomerId { get; private set; }
private List<Entry> _entries;
public IEnumerable<Entry> Entries => _entries;
private CustomerInfo(Guid customerId /* Other properties removed, to
simplify question */){ }
public CustomerInfo Create(/* Other properties removed, to simplify
question */) {
return new CustomerInfo(Guid.NewGuid());
}
/*This is how the entity will control the state of the various lists of
entities that describe it.*/
public Entry UpdateEntry(/* Parameters removed for simplicity */) {
}
public Entry AddEntry(/* Parameters removed for simplicity */) {
}
public Entry RemoveEntry(/* Parameters removed for simplicity */) {
}
}
public class Entry {
public Guid EntryId { get; set; }
/* Other properties removed, to simplify question */
private List<Widget> _widgets;
public IEnumerable<Widget> Widgets => _widgets;
private List<Trinket> _trinkets;
public IEnumerable<Trinket> Trinkets => _trinkets;
private List<ThatThing> _thatThing;
public IEnumerable<ThatThing> ThatThings => _thatThing;
private List<ThisThing> _thisThings;
public IEnumerable<ThisThing> ThisThings => _thisThings;
private List<TheOtherThing> _theOtherThing;
public IEnumerable<TheOtherThing> TheOtherThings => _theOtherThing;
private Entry(guid EntryId /*This constructor will take more parameters,
it's simplified for my question*/) { }
//Create a new instance of a Entry entity
public Entry Create(/* Parameters removed for simplicity */) {
return new Entry(Guid.NewGuid());
}
//This is how the entity will control the state of the various lists of
entities that describe it.
public Widget UpdateWidget() {
}
public Widget AddWidget() {
}
public Widget RemoveWidget() {
}
private bool CanAddAWidget() {
/* Logic to prevent a widget from being add if any of the other
lists have items*/
}
public ThisThing UpdateThisThing()
{
}
public ThisThing AddThisThing()
{
}
public ThisThing RemoveThisThing()
{
}
private bool CanAddAThisThing()
{
/* Logic to prevent a widget from being add if any of the other lists
have items*/
}
}
이 질문은 http://codereview.stackexchange.com/에 더 적합합니까? – VoiceOfUnreason
당신은 TPC (Table per Concrete Type)라는 EF 상속 모델을 설명하고 있습니다. 기본 클래스에서 클래스 상속을 정의하고 코드를 공유 할 수 있지만 각 클래스는 실제로 자체 데이터베이스 테이블에 의해 백업됩니다 (공유 스키마는 각 테이블에 복사됩니다). 그것에 대해 자세히 알고 싶다면 https://weblogs.asp.net/manavi/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-3-table-per-concrete-type을 참조하십시오. - 전략적 - 지침 - 선택 전략. –
안녕 페드로, 당신은 TPC에 이것을 적용 할 수 있지만 그건 내 질문에 관한 것입니다.데이터 지속성은 여기에서 중요하지 않습니다. 도메인 모델링에 초점을 맞추고 있지만 입력에 대해 감사드립니다. 매우 감사드립니다! – GregL