Operation Description getOptions($pollid) Given a pollid returns an
Operation Description getOptions($pollid) Given a pollid returns an array of optionIds for the given poll getOptionName($optionid) Given an optionId returns the name of the option getOptionVotes($optionid) Given an optionId returns the number of votes for that option addVote($optionid) Increments the number of votes of the given option addOption($pollid,$name) Adds an option to a poll removePoll($pollid) Deletes a poll and its options removeOption($optionid) Removes an option from a poll setCurrent($pollid) Sets the given poll as the current poll We can encapsulate all these functions in a Poll_Data class, which uses a DB object to access the database. If we change the database from MySQL to PostgreSQL we just instantiate a PostgreSQL DB object and the Poll_Data class will work without modifications. The Logic Layer We can identify two different logic modules in the logic layer. Firstly, an administration module where polls can be created, options added and removed, the current poll can be selected, and so on. This can be implemented as simple HTML forms using the presentation layer to draw the forms and the data manipulation layer to operate with the data model. Finally, we need an application module where the user will see the actual poll, vote, and then see the poll result. We do not take care of a user voting more than once in this simplified application. So we can create a Poll_Admin class with all the administrative functions and forms to display in a browser and a Poll_Application class with the functionality to show the poll, process the vote, and show the results. The Presentation Layer In the presentation layer we’ll build an HTML class to generate forms, to display the form, to create tables, and so on. This will be a highly generic class that will grow a lot as we create new applications requiring new presentation features. The data presentation component will have methods to display the poll form, to show the results, and to create forms. This class will be a client to the HTML class: the idea is that no HTML code at all will be present in the data presentation class (only calls to the HTML class are used). The Classic Multi-Tiered Architecture Let’s take a look at what happens if we design and create our poll application using this architecture. First, we can see here that we have a strong separation between the content layer, the logic layer, and the presentation layer. We also achieved independence of the database using the DB abstraction class and independence of the presentation language using the HTML class. Let’s see what happens if we have to modify the application. Case 1: The Poll Result Display Changes We used a table showing the options, the number of votes, and the results. The designers decide they now want to display a graphical representation of the percentage of votes in each option. Using this architecture, we just modify the data presentation layer to use functions in the HTML class Page 539
Hint: If you are looking for good and high quality web space to host and run your java application check Vision java web hosting services