1

I'm modeling the "Domain" Layer of "Clean Architecture" for an application that gets its data from an XML file when starts.

The XML file looks like:

<?xml version="1.0" encoding="UTF-8" ?>
<BluePrint>
    <BluePrintVersion>1.0</BluePrintVersion>
    <BluePrintMaxMetaData>500</BluePrintMaxMetaData>
    <ZoneData>
        <MetaDataId>0</MetaDataId>
        <ZoneConfigs>
            <ZoneInfo>
                <Model>
                    <Name>Simple<Name>
                    <DetailedName>Simple model<DetailedName>
                </Model>
                <MetaDataId>1<MetaDataId>
            </ZoneInfo>
            <ZoneInfo>
                <Model>
                    <Name>Medium<Name>
                    <DetailedName>More than simple model<DetailedName>
                </Model>
                <MetaDataId>2<MetaDataId>
            </ZoneInfo>
        </ZoneConfigs>
    </ZoneData>
...
</BluePrint>

Based on above I had the following entities (in C#):

public class Zone
{
    public short MetaDataId{get;set;}
    public float Value{get;set;} //Not specified in XML but this comes from MetaData through MetaDataId
    public ICollection<ZoneInfo> ZoneConfigs{get;set;}
}

public struct ZoneInfo
{
    public struct Model
    {
        public string Name;
        public string DetailedName;
    }
    public short MetaDataId{get;set;}
    public float Value{get;set;} //Not specified in XML but this comes from MetaData through MetaDataId
}

public struct MetaData
{
    public short Id{get; set;}
    public string Name{get;set;}
    public float Value{get;set;}
}


public struct BluePrint
{
    public string Version{get;set;}
    public int MaxMetaData{get;set;}
}

So that I could have MetaData, Zone and BluePrint repositories in "Infrastructure" and "Persistence" layers.

However it turns out that XML files have versions and between one version and another the definition of elements can change. The only inmutable element is "MetaData". For example, XML element <ZoneData> can change to something like:

...
        <ZoneData>
            <ZoneConfigs>
                <ZoneInfo>
                    <Model>
                        <Name>Simple<Name>
                        <DetailedName>Simple model<DetailedName>
                    </Model>
                    <MetaDataId>1<MetaDataId>
                </ZoneInfo>
                <ZoneInfo>
                    <Model>
                        <Name>Medium<Name>
                        <DetailedName>More than simple model<DetailedName>
                    </Model>
                    <MetaDataId>2<MetaDataId>
                </ZoneInfo>
            </ZoneConfigs>
            <CustomConfigs>
                <CustomValue>
                    <Name>Custom0<NAme>
                    <Value>0<Value>
                </CustomValue>
                <CustomValue>
                    <Name>Custom1<NAme>
                    <Value>1<Value>
                </CustomValue>
            </CustomConfigs>
        </ZoneData>
...

So my question is: Should I keep "MetaData" object as the only entity in "Domain" layer and the rest would be formed in "Application" layer depending on XML file version provided?

  • The domain layer is where you put your business rules. The behavior of your objects. If you’re just parsing an XML file and storing it in a database, you don’t need a domain layer. – Rik D Mar 3 at 22:40
  • Well, the XML file is the database. But the applications needs to be capable of handle different versions of XML file. – trofinao Mar 5 at 3:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.