[Techtalk] object oriented references

Jacinta Richardson jarich at perltraining.com.au
Thu May 8 10:41:15 EST 2003

On Wed, 7 May 2003, Emma Jane Hogbin wrote:

> Hey all
> I'm looking for some intermediate-level help with OOP. I've read many many
> intro level articles on OOP, but now I'm looking for something more
> in-depth. I'm currently working on a project that is far more advanced
> than the articles I've seen. I'm happy to read books or articles or
> whatever. Maybe a first year comp-sci text book?

I don't know what level intermediate is.  I know that sounds silly but
basically I don't know what you know and don't know, and therefore I don't
know where to start in telling you stuff.

Nevertheless I'll give you some links I think you'll find useful.

	- look at the OO Perl notes and read the first few chapters as a
	  brief introduction to/reminder of OO.  The rest of the notes deal
	  with OO specifically in Perl, which might be of interest but is
	  probably not what you're looking for right now.

	- an article I wrote about Where/When is OO useful.  The comments
	  after it come with lots of good ideas.

	- Damian Conway's (a big-wig in Perl development) 10 rules of when
	  to use OO.

	- A brief comparison between OO and Imperative programming styles.
	  Very useful to change your world view.

I know that many of these things are at the new-to-OO level, but the fact
is either you understand OO or you don't.  There isn't much of a half-way
point.  I suggest you read them because they might help you spot where
you'vemake your mistakes...

> The project I'm working on is an online quiz editor. I have a Quiz object,
> a Part object and a Question object. I'm trying to understand which
> functions should go in which parts. I had everything figured out nicely
> but in reality it's *slow* because of the choices that I've made. (e.g.
> questions are always pulled one at a time from the database because of the
> way the Question object was designed -- nice in principle, AWFUL in
> practice.)

Perhaps you need a Questions class as well.  Which may be a container for
each Question object.  In the big-ugly project I mention in the article
"When/Where is OO useful" we ended up having Hosts objects as well as Host
objects.  Domains objects as well as Domain.  Subnets and Subnet.  We had
to have.  So the code would basically say:
	my @subnets = Subnets->get_all();

or similar.  The Subnets object would bless all the subnets into Subnet
objects, but did all the management of numerous Subnets.

As for what functions should got into Part, Question, Quiz... well that
depends on what these things mean.  Perhaps you can give us object

Each quiz has a number of sections or Parts.
	- number of Parts.
	- list of parts?

Each part consists of a number of questions.
	- number of questions
	- list of questions?

Each question consists of a question, possible answers (multiple choice),
correct answer... other stuff.
	- question
	- possible answers
	- correct answer
	- ...

If this is your layout (and obviously I'm guessing) it seems clear to me
that your Part object forms the role of the Questions class that I
mention above.  That is, your Part object has the object method
get_questions which pulls all questions out of the db and instatiates each
new question.

Maybe you'll disagree.  In which case you create a class method (note
this is not an object method) on the Question class which does the same
thing - pulls all the data out of a db instantiates a bunch of question
objects and returns the list of them.  

(If you're unclear on the difference between class and object methods
they're covered in detail in the Perl Training Australia notes that I
included in my list above).

> Any suggestions for resources would be much appreciated. I don't mind what
> programming language they're written for as long as they're generic
> enough to be applied to other languages. Right now I'm fluent in PHP (what
> this project is done in), Perl, Javascript and MOO.

Unfortunately, you do have to care a bit about what programming language a
resource is written for.  OO in Visual C++ is vastly difference from OO in
Python which is vastly different from OO in Perl which is vastly different
from OO in Java...  Frankly I know nothing about PHP's object system.  I
don't know whether it allows both object methods and class methods, or how
it handles inheritance (which probably won't be an issue in this case) and
all the fun stuff in inheritance (multiple/diamond...).  I know a lot
about it in Perl which lets you do just about all of OO if you want to.
That's not going to be so useful though.  :(

Sure, the concepts might be similar, but some might not be implementable.
Still, I hope the above can be of some use to you.

All the best,


   ("`-''-/").___..--''"`-._          |  Jacinta Richardson	    |
    `6_ 6  )   `-.  (     ).`-.__.`)  |  Perl Training Australia    |
    (_Y_.)'  ._   )  `._ `. ``-..-'   |      +613 9354 6001 	    |  
  _..`--'_..-_/  /--'_.' ,'           | contact at perltraining.com.au |
(il),-''  (li),'  ((!.-'              |   www.perltraining.com.au   |

More information about the Techtalk mailing list