I'm putting together some classes as a model for some information (that I'm currently pulling from a website).
The classes are implemented in C# - because in the current version of F# there are no autoimplemented properties. The logic to fill these classes from the website is going to be writen in F#. (Because I like F#, and it works nice for webscraping.)
So since I'm working functionally (I seems to always work functionally there days even in C#). I don't want these objects to be mutable. Setting mutable fields is ugly in F# (and for good reason, mutable objects are evil).
So all there data fields have only private setters but this makes my constructors long. I planned to be using named arguments in them anyway, but still 5 arguments is a lot. And I don't think F# supports object property initialisers anyway.
public class PopularitySplitClassOptionSet : IClassOptionsSet
{
public PopularitySplitClassOptionSet (string description, IEnumerable<ClassOption> popularClasses, IEnumerable<ClassOption> unpopularClasses, int reqPreferences, int minUnpopularPreferences)
{
PopularClasses = popularClasses;
UnpopularClasses = unpopularClasses;
RequiredPrefereces = reqPreferences;
MinUnpopularPrefereces = minUnpopularPreferences;
}
public IEnumerable<ClassOption> Classes
{
get
{
return PopularClasses.Concat(UnpopularClasses);
}
}
public int RequiredPrefereces { get; private set; }
public int MinUnpopularPrefereces { get; private set; }
public int MaxPopularPrefereces {
get
{
return RequiredPrefereces - MinUnpopularPrefereces;
}
}
public IEnumerable<ClassOption> PopularClasses { get; private set; }
public IEnumerable<ClassOption> UnpopularClasses { get; private set; }
}
Edit: Is this good practice? Am I thinking this right?
Also: I wonder if:
public readonly int RequiredPrefereces { get; private set; }
would be better? Or is that not actually a thing you can do?
Related questions:
But this makes my constructors long.
I wouldn't say half a dozen lines is long; but even if it is, so what? \$\endgroup\$