Ballot as Composite
Summary
Implement a ballot for the online voting system.
Use the composite design pattern.
Remember to make the proper factories for component objects,
and make the factories singletons.
Make the ballot fit the requirements of the online voting system
(particularly the need to allow multi-level elections),
but use the simplifications below to take away some
of the complexity.
Simplifications
-
Let's assume elections consist of only YES/NO questions.
No need to manage lists of candiates with "pick one"
rules for this exercise.
An election at one level will be just a list of questions,
and voting is selecting YES or NO for each.
-
No need to worry about issues like voter registration and identification
or any other issues that are not ballot related. Deal with ballot
structure and construction, as well as voting and tallying/reporting behavior.
-
Let's have an interface for a ballot that allows
casting votes and tallying.
Also it should allow adding questions to the ballot (adding
an item to vote on).
-
Of course to fit the composite pattern you need to be able to collect
ballot composites together at each level to make groups.
-
For this exercise write a main test app that simulates
the rest of the voting system by creating a multi-level
ballot and making calls to the cast vote methods.
Then make calls to the tally methods and
produce output to show how the election turned out.
Since the election is multi-level you will need
several ballot objects, but no need to have lots of them.