Getting the Light Bulb to Click on with Data Abstraction and OOP

Those of you that have followed me for years, know I am a bit of an Old School Guy. But with WinDev I have finally seen the light and am starting to do more and more class coding. Those classes have been what I would call utility classes, they managed bits of the UI (like my Peek-A-Boo browse form manager) or encapsulation reusable logic (like my Business Rules Manger).

I have always struggled with the Academic Data Abstraction type classes. I just never could get my head around them. I suspect it’s because I am a SQL guy I have just spent to many years with the data and have a hard time not thinking in 3rd normal form. I am glad to say the light bulb has finally came on for me this week.

I am working on rewriting pcReminder.com from its very old Cold Fusion cold to WebDev. At the heart of the site its a list of reminders, and most of the UI is just presenting those reminders in different ways and allowing the user to edit them. This gets a little more complicated because the site support recurring reminders, so the UI has to present reminders that are not really in the database. For instance a reminder that repeats every Friday, is only in the database once, but on all of the calendar views it need to be there for every Friday.

The existing site accomplished this with a stored procedure that builds a temporary table, generating all the reminders to present, including all instances of recurring reminders for the current time frame being viewed. (I did mention I was a SQL guy right!). Although this method has worked well for me for many years, It’s not without its problems, not the least of which is there is a round trip to the database every time the user changes their view.

The back-end database of the site will be changing from SQL Server to PostgreSQL has part of this rewrite. And since the UI is always the toughest part of a web project (at least for me), I have been working on creating the UI for the site without having any database at all. So as I started to get to the point in the UI that I needed to present data, I decided to go with the Class approach and for now just populate my class with some data to work with.

And Now for the Payoff

A funny thing happened, since I was working on the UI and presentation, I was thinking about how I needed my data structured for that, instead of in 3rd normal form for the back-end. My resulting class is taking shape as a nice Data Encapsulation Class and I believe when I get to the point of actually moving it in and out of the database the resulting database design will even be better.

So Uncle Pete’s Tip for the day is:

“If you are struggle with OOP Data Encapsulation, instead of looking at your database and trying to figure out how to create a class for it, and instead look at your UI and figure out how to create a class for It.”
 

I know that probably what all those OOP Enthusiast have been telling me all along but I couldn’t hear them for all the noise in my head.

Once last Note before I let you go, this is not an endorsement of the “Code First” model that I see a lot of .NET folks push these days, at least not in the way I have seen it presented. Once your classes are done, YOU should do the work to figure out how to store the data in the database, and how to retrieve the data and get it into the class. Letting the database structure be generated by the system just seems like the road to damnation to me. But of course I did say I am an Old School SQL guy, so there only so far I am going to bend.

Now, back to your regular schedule program….

One thought on “Getting the Light Bulb to Click on with Data Abstraction and OOP

  1. that is a key feature, for many years we used to setup Views/Table functions and Result Files in CW to get this type of thing done… with WD class’s, I can put Correct RI in the DB, Critical Business Logic there, and keep my UI logic and definitions where it belongs, in the program

    Like

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s