Moving to Code from a Design Model
Application coded with PHP
- Design assumes object-oriented (OO) language used for implementation
- PHP is not a fully object-oriented language, but:
- Has classes with member variables and member functions, similar in approach
to C++
- Allows inheritance, some encapsulation
- Translation to PHP from OO design not a major problem
Code classes follow from Design Model
- SurveyMaker- interface between user and application
- member variables:
- surveyOwner- user name of user
- numSurveys: integer representing number of Surveys surveyOwner "owns"
- filelist: an array of filenames of size = numSurveys
- member functions:
- showSurveyMenu()- choice of
- newSurvey()- creates a new survey, as PHP doesn't have constructor
methods
- modifySurvey()- opens an existing survey for modification
- makeQuestion()- make a new survey question
- modifyQuestion()- modify an existing survey function.
- endSurvey()- quit making survey
- Survey- a container for multiple objects of the class Question
- member variable:
- numQuestions- total number of questions in survey
- member functions
- getNumQuestions(), setNumQuestions()- the usual functions for getting
and setting member variables
- getQuestionTypes()- gets current list of Question Types and associated
parameters from disk
- newQuestion()- adds a new question to the survey
- modifyQuestion()- modifies a question currently in the survey
- refresh()- redraws survey with updated questions shown
- saveSurvey()- Called when data must be saved to disk
- exitSurvey()- closes survey
- Question-
- member variables:
- qtext- String of question text
- qtype- instance of QuestionType class, encapsulates QuestionType
data
- member functions- the usual functions for getting and setting member
variables
- getQuestionType(), setQuestionType()
- getQuestionText(), setQuestionText()
- QuestionType
- member variables:
- questionCategory
- numChoices- number of choices a user pricks from
- numResponses- maximum number of responses a user can make to the
question
- choice[numChoices]- vector of labels for each numChoices
- member functions:
- getCategory()
- setCategory()
- getNumChoice()
- getNumResponses()