Page 20 - MSDN Magazine, July 2018
P. 20

Figure 5 Getting Questions from QuestionService
so long as it can yield back different arrays of Question objects, I have an infinite number of questionnaires I can ask our conference attend- ees. The only restriction is the kinds of questions I can ask right now, being limited to either multiple-choice or open-ended-text answers.
That raises a second question: How hard would it be to add new types of questions into the system, such as a ratings control with discrete numeric values? To do so would require the creation of a new Question subclass (RatingsQuestion) with the numeric range to use, a new ControlType enumeration value for the template to switch on, and modifying the QuestionComponent template to switch on the new enumeration value and display the HTML accordingly (however that would look). Everything else would remain untouched, which is the goal of any component technology— keep the client unaware of any structural changes unless they choose to take advantage of the new features.
Angular readers will be itching to give this whole concept a spin, so I’ll bring things to a close here. However, there’s one more nec- essary bit we need to go over before we can wrap up our Angular coverage, so we’ll hit that next time. Until then, happy coding! n
Ted Neward is a Seattle-based polytechnology consultant, speaker, and mentor, currently working as the director of Engineering and Developer Relations at Smartsheet.com. He has written a ton of articles, authored and co-authored a dozen books, and speaks all over the world. Reach him at ted@tedneward.com or read his blog at blogs.tedneward.com.
ThaNks to the following technical expert: Garvice Eakins (Smartsheet)
@Injectable()
export class QuestionService {
getQuestions() { return [
new TextboxQuestion('', 'firstName', 'Speaker\'s First name', true),
new DropdownQuestion('', 'enjoyment',
'How much did you enjoy this speaker\'s talk?', false,
[
{key: 'great', value: 'Great'},
{key: 'good', value: 'Good'},
{key: 'solid', value: 'Solid'},
{key: 'uninspiring', value: 'Uninspiring'}, {key: 'wwyt', value: 'What Were You Thinking?'}
]), ];
} }
resource like a file or a server-side API. In this particular example, the service pulls the question from memory, as depicted in Figure 5. Obviously, in a real questionnaire, a few more questions are likely,
but this example gets the point across.
Wrapping Up
The real question pertaining to any sort of system like this is its exten- sibility: Can I add new questionnaires without requiring significant modification? Obviously, the QuestionnaireService is the key there—
SUPER-FAST AND ADVANCED CHARTS
LightningChart®
Ÿ WPF and WinForms
Ÿ Real-time scrolling up to 2 billion points in 2D Ÿ Hundreds of examples
Ÿ On-line and off-line maps
Ÿ Advanced Polar and Smith charts Ÿ Outstanding customer support
2D charts - 3D charts - Maps - Volume rendering - Gauges
TRYFFORR
www.LightningChart.com/ms
FREEE


































































































   18   19   20   21   22