In a C# ASP.Net Core Web Application I have a Domain Model CentralDesignObject
made up of many component objects & properties, producing a significant amount of derived/calculated values.
This CentralDesignObject
includes a reference to a DesignType
object. This DesignType
determines various fundamental characteristics of the design object, and various calculated values of the design type may have different calculations based on the DesignType
. The component objects/properties that make up the CentralDesignObject
remain consistent across design types.
CentralDesignObject{
public Guid DesignObjectId {get; set;}
public int DesignTypeId {get; set;}
[ForeignKey("DesignTypeId")]
public DesignType {get; set;}
public ICollection<RelatedDataA> RelatedDataA {get; set;}
public ICollection<RelatedDataB> RelatedDataB {get; set;}
public CalculationMethod_X() {
if (DesignType.Name == 'foo') {
// do x
return x;
} else if (DesignType.Name == 'bar') {
// do y
// Slightly different result
return y;
}
}
}
Currently the number of design types is small, and where the DesignType
may have an effect on calculations, looping and applying conditional logic based on this type is relatively effective.
The current structure puts CentralDesignModels
in a single database table which is straightforward/simple for querying these CentralDesignModels
in various areas of the web-application.
It seems as though separating CentralDesignModels
of the various DesignTypes
into individual concrete types would provide benefit through compartmentalization of logic. A way of achieving that could be to be making the CentralDesignModels
into an interface from which the specific types of CentralDesignModels
inherit. However this seems as though this would complicate other areas of the web-application such as the database structure and querying mechanisms.
What approach do you think would be most valid in this situation? Does the current approach appear valid or problematic? Is there a clear way / design pattern that would allow me to organize this data so that the database structure may remain simple, while the logic of the various DesignTypes
may be compartmentalized in discrete classes?
Any pointers or references no matter how basic or fundemental are appreciated, thank you.
CentralDesignObject
as a constructor parameter, for example a text document writer class. Would the approach here be to refactor those classes constructor parameters replacingCentralDesignObject
with an Interface from whichCentralDesignObject_X
andCentralDesignObject_Y
inherit?