Designing the Poll Application We will now see

Designing the Poll Application We will now see a small example illustrating all the different layers and how to abstract them. We will work with our sample polls application that has polls and a current poll. Each poll has options, and when the user votes, the result of the poll is shown. Designing the Data Model We will use a database for storage so we are going to use a relational model for this application. The tables will have the following structure: polls pollid INTEGER(4) question VARCHAR(80) poll_options pollid INTEGER(4) optionid INTEGER(4) optname VARCHAR(80) votes INTEGER(4) The following script will create these tables: CREATE TABLE polls( pollid INTEGER(4) NOT NULL AUTO_INCREMENT, question VARCHAR(80), PRIMARY KEY(pollid)); CREATE TABLE poll_options( pollid INTEGER(4) NOT NULL, optionid INTEGER(4) NOT NULL AUTO_INCREMENT, optname VARCHAR(80), votes INTEGER(4), PRIMARY KEY(optionid)); CREATE TABLE current_poll( pollid INTEGER(4)); The Content Layer We’ll build the access component for a MySQL database. Here we do not cover the creation of the class since we don’t want to create a working example in this chapter, just the skeleton. We must implement all the operations to our data model in the data manipulation component: Operation Description createPoll($question) Creates a poll returning a pollid getCurrentPoll() Returns the pollid of the current poll Page 538
Note: If you are looking for good and quality webspace to host and run your java application check professional java hosting services

Comments are closed.