| author : | Nolwenn Rannou <rannou@codelutin.com> |
|---|---|
| revision : | 2773 |
| date : | 2009-09-09 12:05:20 +0200 (mer., 09 sept. 2009) |
This part describe the VoteCounting module implementation.
There are 2 interfaces :
The VoteCounting DTOs (Data Transfer Object) allow to use correctly the interfaces exposed by the VoteCounting module.
There are two important root DTOs :
choices.
PollExportDTO have been added for exports. It conatines a PollDTO and several VoteCountingResultDTOs.
Two enumerations are also available and allows the types normalization :
Please note that the VoteCountingType is used as reference for a poll vote counting.

PollDTO
It is coumpounded of PollChoiceDTO (the poll's choices) and Comment DTO (the poll's comments).
It is compounded of VotingGroupDTO. This one correspond to group of voters in case of a group typed poll. In case of another type, there will be one and only one VotingGroupDTO with null values (weight and idGroup).
Each VotingGroupDTO is compounded of VotingPersonDTO corresponding to voters linked to the poll (people who have already voted). The votingID will be "anonymous" in case of an anonymous poll.
Each VotingPersonDTO is compounded of VoteToChoiceDTOs corresponding to the voter's votes (for each choice a value).
It is not necessary to know all the choices in advance at the poll's level. The vote counting will manage the organization of the results regarding the choices.
VoteCountingResultDTO
The results are shared out according to the poll's choices. A ResultDTOV is compouded of ChoiceDTOVs corresponding to those choices.
So for a poll we have :
This operation allows to execute a poll's vote counting.
This operation allows the execution of a poll's vote counting functions of groups.
The Strategy Pattern is used to manage the vote counting. A Context class allows to define which strategy type to use. The strategy is defined at the beginning with PollDTO's typeVoteCounting attribute.
Here the strategies are represented by the Method interface that will be implemented by :
Each method implements the "executeMethod(choices)" operation that will be called in the Context class by the "execute()" method. So the context needs to know all the choices and the votes by choice and by group.
When calling for ServiceVoteCounting, a new context will be created and the PollDTO will be scanned to create the choices, groups and votes needed for the vote counting.

(with group adding to the context Context.addGroup(idGroup, weight)) - Scan VotingPersonDTO : For each people -> VoteCounting.routePerson(VotingPersonDTO) - Scan Vote : For each choice -> add it to the context via Context.getChoice(idChoice).getGroup(VoteCounting.currentIdGroup).addVote(value, weight) - Execute the vote counting method -> Context.execute() - Create the VoteCountingResultDTO that contains all the choices with their results.

With a classical vote counting, the winner is the one that has the biggest number of voices. With the Condorcet method that is not necessarily the case. The winner is the one that, compared to each other candidate, is always prefered. In certain situations, such a winner does not exist, this is what we call the Condorcet paradox (A>B>C>A). The algorithm chosen in Pollen consit in chosing the candidate that won more duels. In case of deuce a vote needs to be done between the leading group.
A condorcet vote sequence is the following :
number of wins of each candidate 3. The winner is the one that have the greatest number of victories.
In Pollen, the implementation of Condorcet vote has in addition the notion of voters groups. In cas of vote counting by groups, the algorithm is applied for each groups, and then applied a second time between the results of each group. When the voters vote in a poll, they can make two choices equals. It is not necessary to sort all the choices, those which are not ranked will be all last.
This is the main operation that allows the poll export, the object given in parameter contains the poll object and a list of the results to export. Those results are obtained by the different vote counting methods. This methods returns the name of the exported file.
This operation imports the poll and its results from the file which path is given in parameter, so it builds the PollExportDTO return by this method.
An easy implementation have been made for this part. Itturns out that the Visitor pattern use is significant for this module implementation as it works the same way that the Visitor pattern, but to do so, we need to add methods to the DTO classes that violates their semantics, so we proceeded as shown in the following diagram.
