vendredi 13 mai 2016

If an object parse it's own input, is it considered breaking SRP?

If an object parse it's own input, is it considered breaking SRP?

For example

class A
{
    int x;
    string y;
    float f;
    A(string x, string y, string f)
    {
        this.x = int.Parse(x);
        if (this.x < 0 || this.x > 10)
        {
            throw new ArgumentOutOfRangeException();
        }
        this.y = y;
        this.f = float.Parse(f);
    }
}

Instead of passing an int, string and float and parsing and checking if they're valid somewhere else.

Aucun commentaire:

Enregistrer un commentaire