I'm an average perl programmer. I haven't problem with the language itself, but with the "good" object design. While I'm able understand (most of) CPAN modules, without serious problems, i'm unable design myself even the simple object hierarchy.
Example - now facing an really simple application (web and command line interface):
- the already authenticated student uploads a zip-file (what contains an rendering job)
- unzip the file to and new directory and check it's content (should contain exatly one file
commands.txt
) and zero or more images - if the content is OK - move the directory to place called:
JobRepository
(another directory) - if the user decided to run the rendering job - send the job from his own
JobRepository
to global rendering queue (again, another directory) - another process takes the jobs from the queue (fifo - designed with IPC::DirQueue) and execute the rendering process
- when finished, put the result into the users
JobRepository/result
directory - send email to the user
- the student can download the zipped results
In bash
it is doable with few "not to complicated" bash script - but i want do it in Perl (because web interface) - and want practice perlish (Moose) object design…
And here starts my problems.
Tried "visual" noun-analysis approach and make the next image.
Posted the image, because it is "shorter" as:
package Iren::JobRepo;
use Moose;
use warnings;
has 'Jobs' => (is => 'rw', isa=>ArrayRef[Iren::Job]);
…
method AddJob {
...
}
etc.
As you can see, it is really simple - but immediatelly facing some decision problems, e.g.:
- what object should do the unzip/zip/checkJob methods? It is belong to: JobRepository ot the Job "zips" itself?
- what object should send emails to User? the
$user->send_email
- comes me silly, because we sending email TO users and not the user to itself… - "who" should send the Job from the user's JobRepo to RenderQueue? The
JobRepo->SendJobToRenderQueue
or i should call someRenderQueue->addJob
method? - what object should should use the ISA
IPC::DirQueue
- (should be the implememtation of RenderQueue) - circular definitions. The User has JobRepository, The Repository has many Jobs, but the Job has? an User? (need to know to whom belonging the job) - and so on..
As you can see, no Roles, no Traits here - nothing - it is simple… - but full of questions :(
Can anybody help clear the mess? What should be the "good" package hierarchy?
So, i'm really lost and I have started to disappointed myself. Additional questions (i know, these are opinion based) - but I must ask them...
- How to learn good object design for perl/Moose? (I'm probably will never use another language)
- searching google about object design (and Stackoverflow too) many times are cited the "Gand of Four" book (and few others). But usually for Java. It is worth to buy for the perl/Moose? Or is here some another good books for perl/Moose?
- is some good technique how to check the proper object design?
- code generators from UML probably doesn't exists for Moose - or is here something usable and recommented?
- simply - how do you mastering your object hierarchy/Roles/Traits etc…? While i'm reading the examples - I understand the
$cat->diets
:) - but mastering something new - is bad for me…
Sorry for the wall of text. I would be much happy getting any pointer to good book or anything what helps...