![]() |
|
Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re^3: Thorny design problemby Tanktalus (Canon) |
on Sep 07, 2005 at 23:22 UTC ( [id://490029]=note: print w/replies, xml ) | Need Help?? |
I'd be very careful about this. Because if you look for similarities, there likely will be many. I realise that the idiosyncracies probably outweigh the similarities, but even encapsulating those few similarities (which, of course, won't be similar among all companies, but probably a significant subset will share one similarity while another subset shares another similarity, etc.) can pay dividends. For example, what I have done in a similar (yet completely dissimilar) situation ... where I have a bunch of tasks to perform, each one is almost completely unique from the other, and I have a task manager object that reorders the tasks (order can be important for me - not likely for you, but the manager could do other things to help, such as figure out that some companies have been updated recently enough to skip, or something) and then executes them serially. The manager object is actually almost completely uninteresting here. For the most part, that's it. I skipped the sorting part, for example. And strict/warnings - they're in the real module. And then, the Task module looks like this: Now I didn't really show you how to reuse stuff. But what I've started here is a framework. A framework upon which you can build further frameworks. For example: Now you just need to derive your HTTP-gathering info from Task::WWW, override two simpler functions, and can rest assured that if your application needs to change proxies for http requests, they all go through this code and can be easily modified. I realise that LWP::Simple probably uses environment variables for this, but it's just an example. I'm sure the more imaginative out there can find another use for this type of abstraction. Perhaps you now need to authenticate to get out of your company intranet. Or something equally silly. Whatever. By abstracting out the common parts, you not only can save time in adding new requirements like that, but you can concentrate on smaller pieces of the overall puzzle at a time in each function in each module. You'll have well over 100 modules this way, but each one will be simpler. (I think I need to formalise this and put it on CPAN...)
In Section
Seekers of Perl Wisdom
|
|