in reply to Design Question - I've gone object mad!

All my code these days is object oriented, maybe to the extreme I sometimes think!

That alone is worth an upvote.

Personally I've found that modelling data objects (or real life objects) literally is less useful than I'd been taught as an OO whelp growing up.

Far more useful has been to model processes or semantics. i.e. what do you really DO with "Industry" rows? If you start with the literal model then you have to redesign the semantic layer on top of that anyway and you end up with nasty object interrelation soup that abstracts a simple sql statement.

Do you really have such breadth of real world operations on this data that you need universal 1:1 access to the database objects modeled as objects? (You may I suppose.)

That said, you may be committed to this course of action for one reason or another, which would make this "observational commentary" rather than a suggestion ;)

$0.01

Me
  • Comment on Re: Design Question - I've gone object mad!

Replies are listed 'Best First'.
Re^2: Design Question - I've gone object mad!
by Cagao (Monk) on Apr 06, 2011 at 08:48 UTC

    I have come across this thought from my fellow monks in the past, yet I still can't seem to see how, possibly not seeing the woods through the trees.

    In my example, a My::Customer may work in a My::Industry. They'll need to select a My::Industry on a form.

    This all leads me to needing to get a list of possible industries, and tying the two together through their IDs.

    Somewhere else I may need to get all My::Customer objects that registered last month, last year, 2 weeks ago, etc, hence the need for some sort of...

    My::Customer->get( registered => [ DateTime->new( year => 2011, month +=> 4, day => 1 ), '>' ] );

    ...approach.

    I'd love to sit down and talk this idea of modelling processes more than the objects themselves with a fellow monk, but unfortunately I currently work pretty much alone, while training up 2 others.

    I presume my original approach to be "ok", I think I've asked a similar question before and it usually goes on this same tangent of the modelling rather than the interface.

      Somehow, I do not like the '<' string. Cannot you supply a sub ref that will return the values you need, i.e. similarly to sort:
      My::Customer->get( registered => [ DateTime->new( year => 2011, month +=> 4, day => 1 ), \&greater ] );
      You can than define between etc.

        Me neither, that string isn't very nice.

        An interesting approach you suggest, this is what I was after! :)

        Tho that does make the code look a bit messier - maybe some more encapsulation around it...

        My::Customer->get( registered => [ $datetime, My::Operator->greater ] +); package My::Operator; sub greater { return '>'; # or something more fully fledged! }
      Indeed. I'll chime in with the reassurance that there's little "wrong" with the modelling of 'physical' objects.

      It tends to be a bit heavy weighted later on. But refactor it a bit at a time. For instance, everything you describe sounds ok. But I don't have to work with it, so it's tough to figure out where the sticking points are. All I can really advise is to pay very close attention to "I wish I could just...." thoughts. Optimistically write it top-down as far as you can, then the design difficulties will emerge in a pretty clear way.

      Either way, sounds like your thinking on the right lines.

      Me
Re^2: Design Question - I've gone object mad!
by Cagao (Monk) on Apr 06, 2011 at 09:35 UTC

    Just a quick addition, the My::Customer object will translate columns, join multiple tables together, etc, to return a fully fledged My::Customer object.

    I'm not just blindly modelling a database table.

    Like I say, this modelling is, in my eyes, a layer above the database model (if i were to introduce DBIx::Class, for example).

      From this particular description it sounds like you misunderstand what DBIx::Class does out of the box and what it can do with plugins/customization.

      Have you tried it? Do you know it does all those joins and such, in deep, flexible, beautiful ways with chained resultsets, and can do things like manage transactions with nothing but variable scope? Twice in the last few years I’ve been stuck with legacy code written under the auspices of NIH syndrome and I really hold a grudge against the developers who made those choices and wasted weeks and weeks of my time that could have been productive, just chasing bugs and dealing with edge cases. For the future “me”s out there, I’m begging, investigate your options. There are many.

        Hi Mom,

        I'm sure I'm aware of DBIx::Class and what it can/does do, but again it is natively tied to a database, something we may not be using in the future, so for that reason, I am modelling above the database/dbix::class layer.

        My models may well use DBIx::Class internally when they are talking to a database, but that is internal.

        Hopefully you see now that I am designing a layer above the modelling of the storage engine being used.