A theory of parties and electoral systems