It is my first attempt in DDD and I'm trying to wrap my head about this concept. In my examples a lot of validation is omitted for simplicity. I have two types of InterfaceConfigurations:
- VistaLink: outbound interface (must have EndPoint specified, i.e. where outgoing messages go)
- HL7: can be inbound (no need for EndPoint) or outbound (requires EndPoint and FacilityID)
The following how I addressed it in the code. But I wonder if that is too much of inheritance on domain models level (I've seen a number advises to avoid it):
Shared properties are in the base class:
public class InterfaceConfiguration: IEntity<string>
{
public InterfaceConfiguration(string id, string displayName, bool isActive, bool isRequired, InterfaceTypeEnum interfaceType)
{
Id = id;
DisplayName = displayName;
IsActive = isActive;
IsRequired = isRequired;
InterfaceType = interfaceType;
}
public string Id { get; protected set; }
public string DisplayName { get; protected set; }
public bool IsActive { get; protected set; }
public bool IsRequired { get; protected set; }
public InterfaceTypeEnum InterfaceType { get; protected set; }
}
Inbound Hl7 interface with its properties:
public class Hl7InterfaceConfiguration : InterfaceConfiguration
{
public Hl7InterfaceConfiguration(string id, string displayName, bool isActive, bool isRequired,
string fieldSeparator, char[] encodingCharacters, char processingId, string versionId): //there are acually more properties...
base(id, displayName, isActive, isRequired, InterfaceTypeEnum.Hl7)
{
FieldSeparator = fieldSeparator;
EncodingCharacters = encodingCharacters;
ProcessingId = processingId;
VersionId = versionId;
}
public string FieldSeparator { get; protected set; }
public char[] EncodingCharacters { get; protected set; }
public char ProcessingId { get; protected set; }
public string VersionId { get; protected set; }
}
VistaLink interface:
public class VistaLinkInterfaceConfiguration : InterfaceConfiguration
{
public VistaLinkInterfaceConfiguration(string id, string displayName, bool isActive, bool isRequired, IntrefaceEndPoint endPoint)
: base(id, displayName, isActive, isRequired, InterfaceTypeEnum.VistaLink)
{
if (endPoint == null)
throw new ArgumentException(nameof(endPoint));
if (endPoint.AddressType != EndPointAddressTypeEnum.DnsHostName && endPoint.AddressType != EndPointAddressTypeEnum.IPAddress)
throw new ArgumentException("Address type muct be DnsHostName or IPAddress", nameof(endPoint));
}
public IntrefaceEndPoint EndPoint { get; protected set; }
}
And finally outbound Hl7 interface:
public class Hl7OutboundInterfaceConfiguration : Hl7InterfaceConfiguration
{
public Hl7OutboundInterfaceConfiguration(string id, string displayName, bool isActive, bool isRequired,
string fieldSeparator, char[] encodingCharacters, char processingId, string versionId, IntrefaceEndPoint endPoint, string facilityId)
: base(id, displayName, isActive, isRequired, fieldSeparator, encodingCharacters, processingId, versionId)
{
if (endPoint == null)
throw new ArgumentException(nameof(endPoint));
if (endPoint.AddressType != EndPointAddressTypeEnum.DnsHostName && endPoint.AddressType != EndPointAddressTypeEnum.IPAddress)
throw new ArgumentException("Address type must be DnsHostName or IPAddress", nameof(endPoint));
if (facilityId == null)
{
throw new ArgumentException("Facility ID is required for HL7 outbound interface", nameof(facilityId));
}
}
public IntrefaceEndPoint EndPoint { get; protected set; }
public string FacilityId { get; protected set; }
}
I tried to make it more "flat", but not sure how. For example, EndPoint and FacilityID properties of Hl7OutboundInterfaceConfiguration don't make sense for Hl7InterfaceConfiguration (which is inbound only). So that would expose them in unassigned state for Hl7InterfaceConfiguration and potentially may confuse outer functionality.