











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












Start VoterLogin Authentication Not Registered Stop VoterLoginSession Voter GetBallot Election BrowseDocuments DocumentHolder SubmitVote VoterVote VoteList ChangeVote ViewResult ElectionStats Logout Stop SaveAs Update
+AuthenticateIdentity() +CreateAdminLoginSession() +CreateEOLoginSession() +CreateCandidateLoginSession() +CreateVoterLoginSession() Authentication +AddUser() +DeleteUser() +UpdateUserInfo()
+GetElectorate()
The client making the copying/cloning of the ballots is Election, and this is done when a Ballot is requested from an Election instance. Prototype: Prototype ConcretePrototype: Ballot, Question,QuestionField Client: Election Memento in Ballot While working with a ballot requires having a working copy in memory it is only the values of the answers that are of interest when the voter is finished voting, the rest (like the Questions) are not relevant. To solve this problem every Ballot is a Memento where the current state can be extracted and saved separately. This way the program is much more memory efficient which is necessary as there are a lot of votes. The memento contains the answers but also a pointer to the election that the memento is extracted from. Originator: Ballot Memento: UserAnswers Caretaker: VoteList through VoterVote Factory for Authentication of users and voters A user have a handle (UserLoginSession or VoterLoginSession, depending on what login) that is the base handle used to perform all the requests when logged in. But the creation of these handles goes through the process of authentication (user name and password, or a voter id). This process of authentication is centralized in two factories (depending on what login type). If login fails the Factories return null or throws an error. Because authentication to log into the two systems might be quite similar they are placed in the same (static) class, Authentication. ConcreteProduct: UserLoginSession ConcreteCreator: (static) Authentication.userLogin(user, pass) Table 1 : UserLoginSession factory. ConcreteProduct: VotedLoginSession ConcreteCreator: (static) Authentication.voterLogin(voterId) Table 2 : VoterLoginSession factory.
Chain of Responsibility to handle privileges for elections Every Election instance holds a chain of rules of who is eligible to vote. Every such rule implements the interface ElectorateRule, that is a node in that chain. To see if a User instance is eligible to vote in the election a function isEligible() is called down the chain of electorate rules. If anyone of them returns true the user is eligible, else not. Handler: ElectorateRule ConcreteHandler: Ex: ElectorateRuleAge, ElectorateRuleGeo Client: Election Composite to handle region specific elections Elections are most of the time made in different regions, in US for example national election, state election and county elections. An easy way of represent this is through the composite design pattern. As every election basically does the same thing except in different regions, every election is a Component in the Election tree. The top-most (root) Election in the tree is the national election. The bottom ones could be counties. Composite: Election Client: undefined Comment: While Design Patterns: Elements of Reusable Code refers to Leaf and Composite our Composite Design pattern does not distinguish between the two. A leaf is simply a Composite without any children. Factory for candidacy to check creation authentication In our design everyone that are elligible to vote are allowed to suggest themselves as candidates. If a more complex rule system than this would be required it would have been implemented in the similar fashion as the ElectorateRule Chain of Responsibility. A factory (static function in candidacy) takes a user and returns a Candidacy object if the user is elligible to go up for candidacy. Factory for election officer authentication A factory that takes a username and password and returns an ElectionOfficer instance if the user has election officer privileges. ConcreteProduct: ElectionOfficer ConcreteCreator: (static) ElectionOfficer.get(user, pass) Factory for administrator authentication A factory that takes a username and password and returns an ElectionOfficer instance if the user has
File Responsibilities Holds MIME/filetype and file Collaborators ElectionStats Responsibilities Facade to different classes gathering statistics. Collaborators Classes that contain statistics Election ElectionList Responsibilities Holds, removes, retrieves and adds elections Collaborators Election QuestionField Responsibilities Decorator, prototype Holds an answer and controls how this specific answer interacts with the other answers. Holds information about the different possible answers via DocumentHolder Collaborators QuestionField DocumentHolder File
User Responsibilities Holds username and password Keeps track of registered or not Methods for authentication (add/check/drop privileges (strings)) Collaborators Voter Responsibilities An anonymous voter Created when a user registers as a voter Holds a voter ID number Holds geographic information about the voter Implements a method that that returns a list of the ongoing elections that the user is eligible to vote in. Collaborators ElectionList Authentication Responsibilities Factory returning a UserLoginSession on successful login ...or... Factory returning a VoterLoginSession on successful login Collaborators UserLoginSession VoterLoginSession
UserAnswers Responsibilities Memento in the Memento Design Pattern (holds all the answers for a ballot) Collaborators Ballot ElectorateInfoRule Responsibilities Handler (in Chain of Responsibility) specifying rules for who is allowed to vote. Collaborators ElectorateInfoRule Voter Question Responsibilities Prototype Return answer data Collaborators QuestionField DocumentHolder File Election Responsibilities Composite (region) Holds a ballot Holds electorate information (who's allowed to vote) Holds dates Holds the votes Holds a list of candidates Collaborators Ballot ElectorateInfoRule DocumentHolder File Election Candidate
Candidacy Responsibilities (Static) Factory to create a Candidacy object from a User object if sufficient privileges and not exist Holds documents relevant for candidacy Collaborators User DocumentHolder ElectionOfficer Responsibilities (Static) Factory to create an ElectionOfficer object from a User object if sufficient privileges Registers voters Register candidates Delete voters Collaborators User Administrator Responsibilities (Static) Factory to create an Administrator object from a User object if sufficient privileges Delete Candidates Add Election Modify Election (Static) Factory to create an Administrator object Register election officer or administrator Remove an election or administrator Collaborators User
could have added a specific list of administrators and had an own login for them individually. This would have been a lot more code, but maybe a more simple system. Statistics are not gathered in real time, which will make the statistics gathering more computational exhaustive. This decision has been made because of the possibility to change the votes. Two solutions to this problem are: Compute the final statistics when the election is over. Implement a caching Proxy design pattern for the ElectionStats class. The prototype of a Ballot might require a lot of memory usage until the vote it sent and because the questions There are a lot of Mementos of votes. These could be FlyWeight:ed if they take up a lot of space.