Re: design?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/29/06, Sjef <manuals-scripts@xxxxxxxxx> wrote:
Hi there,

Hi Sjef,

First off, I think David has a good point with regards to the OO vs
Procedural approach.  If you're looking to do this quick and easy, it
might not be worth your time fussing with OO.  Unless you'd like to
just for the exercise, which I wholly support, so go for it!

I want to create a class Question for dealing wiht the questions and a class
answer for the answers. Each could contain an array with the their part of
the content of the database table.

As far as how to design it OO-style, I'd first urge you *not* to have
separate classes managing lists of questions and answers.  Say for
example you query your db for questions, build up your array inside
your questions class, and then while doing the same for your answers
class, you inadvertently introduce a looping bug that drops one of the
answers from the array, or possibly changes the order that you create
your array, or any other number of possible mistakes (human or
otherwise).

Point is, in the end you'd have two out-of-synch classes that really
should've been built separately to begin with.  A single question and
it's answer(s) are tied together, so keep it that way in your class
abstraction.

That said, I'd suggest building a question-answer *pair* as a class,
and then you'd have an array of these question-answer pairs
representing your entire list (which could be encapsulated into a
container class if you wished).

You could, to be even more abstract, create base question and answer
classes to represent the most basic type of question or answer, and
then hold individual, **related** instances of these within your
question-answer pair class.  Do you see the difference?

You could even take it a step further and build derivatives of your
base answer class to represent different types (string, multiple
choice with one answer, multiple choice with many answers, etc)...But
I'm sure I'm already getting far ahead of your original design.  But
David started it!  :)

HTH,
John W

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux