A Person class containing a list of Persons
But how does it look from an OOP perspective?


Not very good because it combines multiple responsibilities in a single class. 


the one of a data object as the Person is clear, I guess. The other two are
the repository represented by



private static List&lt;Person&gt; persons = new List&lt;Person&gt;();

public static Person GetPersonById(int id)
{
    foreach(Person per in persons)
    {
        if (per.ID == id)
            return per;
    }
    return null;
}

public static List&lt;Person&gt; GetPersons()
{
    return persons;
}




and the factory represented by



private static int statId;
statId++;



This means that the Person should actually be three classes.

On top of all this you cannot test it because the nested factory is a static one and if you try to write a test validating the statId++ you couldn't because you cannot verfiy that it'll do +1 to the last id because if any other test executes at the same time the result might actually be +2 or even more. You also cannot verify that it correctly adds the new instance to the list because agian, if any tests execute at the same time you could have more then one object added to the list.




id = statId;
statId++;



I find this is not how the id increment should be implemented. statId should not be the next index but the last one. What if you decide to add a property like LastId? You'd have to calculate it first with statId - 1 - ugly. Instead use the prefix ++ like id = ++statId and start with int statId = -1; that is usually considered as na invalid index in many APIs. Then the LastId property could just be LastId =&gt; statId;.