Design Pattern for building a Budget
- by Scott
So I've looked at the Builder Pattern, Abstract Interfaces, other design patterns, etc. - and I think I'm over thinking the simplicity behind what I'm trying to do, so I'm asking you guys for some help with either recommending a design pattern I should use, or an architecture style I'm not familiar with that fits my task.
So I have one model that represents a Budget in my code. At a high level, it looks like this:
public class Budget
{
public int Id { get; set; }
public List<MonthlySummary> Months { get; set; }
public float SavingsPriority { get; set; }
public float DebtPriority { get; set; }
public List<Savings> SavingsCollection { get; set; }
public UserProjectionParameters UserProjectionParameters { get; set; }
public List<Debt> DebtCollection { get; set; }
public string Name { get; set; }
public List<Expense> Expenses { get; set; }
public List<Income> IncomeCollection { get; set; }
public bool AutoSave { get; set; }
public decimal AutoSaveAmount { get; set; }
public FundType AutoSaveType { get; set; }
public decimal TotalExcess { get; set; }
public decimal AccountMinimum { get; set; }
}
To go into more detail about some of the properties here shouldn't be necessary, but if you have any questions about those I will fill more out for you guys.
Now, I'm trying to create code that builds one of these things based on a set of BudgetBuildParameters that the user will create and supply. There are going to be multiple types of these parameters. For example, on the sites homepage, there will be an example section where you can quickly see what your numbers look like, so they would be a much simpler set of SampleBudgetBuildParameters then say after a user registers and wants to create a fully filled out Budget using much more information in the DebtBudgetBuildParameters.
Now a lot of these builds are going to be using similar code for certain tasks, but might want to also check the status of a users DebtCollection when formulating a monthly spending report, where as a Budget that only focuses on savings might not want to.
I'd like to reduce code duplication (obviously) as much as possible, but in my head, every way I can think to do this would require using a base BudgetBuilderFactory to return the correct builder to the caller, and then creating say a SimpleBudgetBuilder that inherits from a BudgetBuilder, and put all duplicate code in the BudgetBuilder, and let the SimpleBudgetBuilder handle it's own cases. Problem is, a lot of the unique cases are unique to 2/4 builders, so there will be duplicate code somewhere in there obviously if I did that.
Can anyone think of a better way to either explain a solution to this that may or may not be similar to mine, or a completely different pattern or way of thinking here?
I really appreciate it.