Pretty Patterns All in a Row

Now that I have things mostly sorted out let's actually do some code or at least some pseudo-code on how I going to make it work.

I could go the pure Perl route and do the same sort of thing DBI does, an interface then drivers under it following this design pattern

pic1.png

I have cloned out and customized the DBI code and pattern in other applications and it really works well when you want the common glue on-top approach.

One thing I want to avoid is API deviation or sub bloat as I like to call it. It is an all to common occurrence with this design pattern. I am guilty of it myself when I added Scrollable Cursors into DBD::Oracle. Nothing in the DBI spec about these and I recall a little note from Tim asking to explain why I didn't create a generic DBI version before I added into DBD::Oracle.

The original JAVA DatabaseAccessor abounds with this sort of bloat. The top level API had only had eight functions while the various implementation layers had many dozens and this carried on with the Perl version that I am now working with.

I would love to put a stop this form of sub bloat before it begins but how? Just the nature of Object Oriented programming I guess you can always add more stuff in than the original programmer intended.

One thing I can do is enforce what the coder has to implement to make things work, and I thinks I can achieve this using Moose and roles.

Now the question is what sort of design pattern am I going to use? Something like this;

pic2.png

The above leads to this sort of calling signature

 
my $address = Database::AccessorX->new({table=>address,...});

Now that isn't what I want as I do not want an end user to be able call up the Accessor class directly. In the Java world we had the Abstract class that can not be invoked but can be extended.

No doubt someone has run into this before because there is 'MooseX::AbstractMethod' which I think does what I want. So I get this sort of design pattern

pic3.png

and a calling signature like this


my $address = DA::Address->new();

Hmm now to try and put that in practice.

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations