Daniel Watrous on Software Engineering

A Collection of Software Problems and Solutions

Posts tagged rdbms

Software Engineering

WordPress plugin licensing: API and class diagram

In the first article in this series, I sketched out some of the basic design ideas for the wordpress plugin licensing system.

The next step is to come up with some more concrete details about how the application will work, what information it will manage and what the interfaces will look like when accessing it. I really like using the UML as I flesh out a design. In particular I find the class diagram and activity diagram useful.

I frequently make use of stereotypes to extend the meaning of my classes. I’m not sure if this is exactly how the UML was intended to be used, but it’s really helpful. At times I also use simple tables, hand drawings, etc. if it helps capture an important point.

Here are the first design documents showing the classes I have in mind for the application and the RESTful API that will provide access to them.

Classes and API

Design choices

My initial design included normalized classes for Licensee, Product and LicenseTemplate. This would prevent duplication of licensee data across multiple licenses and would facilitate reporting by liensee and product. I also had APICall associated with AdministratorAccount since each API call could correspond to various objects in the system.

As I fleshed out the API, a few drawbacks came to mind regarding the normalization I mentioned above. First was the additional complexity in managing all of the normalized classes and associating parent and child objects. Since I am not targeting an RDBMS, the traditional SQL joins and other query approaches don’t benefit me with properly normalized design. I can make the application much more performant and simple by keeping everything in a single SiteLicenses container as shown.

Next design steps

You can see from the diagram above that I haven’t begun assigning responsibilities yet. However, it’s easy to see already where some of the key responsibilities, like isPremiumAccount(), getSiteLicenses(), revokeLicense(), getAPICallsMinutes(Integer minutesBack), etc. will end up.

Software Engineering

Roadmap to Become an Expert Object Oriented Programmer

Programming has evolved in very significant ways over the last few decades. There have been some significant strides forward in terms of language structure, reduced complexity and programmer productivity. One of these shifts was from procedural style programming using a language like C to object oriented programming using a language like C++.

Most modern languages support objects, inheritance and other object oriented constructs. However, not all programmers use these the right way.

As a matter of course, most introductory material in programming is procedural in style (a linear sequence of commands). It’s important as a programmer to move beyond this procedural style when the software calls for it (yes, there are times when a procedural approach is preferable).

The best place to start is with The UML, then on to object oriented design, relational databases and finally to object-relational mappers. Here’s a roadmap with some links out to resources.

The UML

Years ago Borland published a tutorial for the UML that is still a great introduction to the topic:

http://edn.embarcadero.com/article/31863

I’ve also read Sams Teach Yourself UML in 24 Hours. It was published in the early 2000’s and I found it helpful. I think the most effective UML training has come to me while reading books like the ones I mention below.

ArgoUML is an amazing free tool that you can use to create and explore UML models. In practice I’ve found that UML modeling is most effective in two cases. The first case is where a functional code base already exists and requires modifications. The second case is where the bulk of the design has been done long hand on paper. I very rarely (almost never) start with a tool like ArgoUML for initial design. I’ve also found that modeling one component, then implementing it before modeling other components is useful. I think this is called an Agile approach nowadays.

http://argouml.tigris.org/

Object Oriented Programming/Design (OOP/OOD)

This would be a good starting point to learn about Object Oriented Programming (typically abbreviated as OOP):

http://www.google.com/search?aq=2&oq=object+oriented+programming+tutorial&sourceid=chrome&ie=UTF-8&q=object+oriented+programming+tutorial+python

While the types of tutorials that you find using a query like the one shown above may be helpful, they only scratch the surface of what OOP really is and how it is to be done. In order to really understand it you’ll need a good book (or a few, but it’s good to take it a step at a time). Some books that were extremely influential for me include

Thinking in Java 3rd edition by Bruce Eckel. You can get this for free in electronic format:

http://www.mindview.net/Books/TIJ/

Here’s the download page: http://mindview.net/Books/DownloadSites/

Obviously this book discusses Java, but it’s important to recognize that in the evolution of programming languages, Java really descends from C (C >> C++ >> Java).  At least Sun had in mind to arrive at a language that would improve programmer productivity and eliminate some of the common pitfalls in C++. In large measure they accomplished this. Bruce Eckel discusses some of this in the Preface. The book also comes with code samples, solutions, etc. You can use the Eclipse IDE to explore the examples.

Patterns of Enterprise Application Architecture by Martin Fowler:

In this book he offers a very practical view of how to implement enterprise software. Enterprise software isn’t necessarily different than any other software except that the problems it solves are more commonly found in the enterprise. Many of his examples in that book deal with financial and transactional processing. Dave currently has my copy of this book.

Of course there’s the seminal work by the Gang of Four simply called Design Patterns. Most of the discussion and examples are in smalltalk. Despite the age of the language, the patterns are still very pertinent to software design.

Data Persistence

The use of databases to persist data is widespread. There are various types of databases, but the most common by far is the Relational Database Management System (RDBMS). Examples of this type of system include MS SQL Server, Oracle, MySQL and PostgreSQL, to name a few. There are many many more. There have been many efforts to create object oriented databases, but these failed to gain traction due to speed and complexity. Recently, however, there has been a new movement in the direction of object databases (notice I didn’t say object oriented). An object database stores data as an object, but doesn’t necessarily provide mapping between objects.

I’ve read and can recommend two books on database design.

Data Model Patterns: Conventions of Thought by David C. Hay. This is to database design what Fowler’s PEAA is to object oriented software design. He masterfully details mature database models that accommodate a wide range of domains. In the final chapter he provides effective clarification on some points about nomenclature and design approach. This is helpful when extending or adapting the data model patterns found throughout the book.

Database Design by Ryan Stephens and Ronald Plew. This is an overall view of database design, including normalization. This book also covers the process of domain identification and some nuts and bolts of how SQL and RDBMS’s work. The chapters dealing with analyzing and modeling business components is the most useful and has carry over into object oriented design (OOD).

Obejct-Relational Mapping (ORM)

Once you have a good grasp on OOD and RDBMS’s, the most logical next step is to explore the various object-relational mapping tools. Fowler explores Data Mapping patters in PEAA. My first exposure to object-relational mapping was with Hibernate: http://www.hibernate.org/. I originally purchased and read Hibernate in Action by Christian Bauer and Gavin King back in 2004. While the project has come a long way since then, the core principles as defined in that book haven’t changed. PEAA is probably the best place to explore object-relational mapping.

Obviously there’s a lot more to becoming an expert object oriented programmer than just these concepts, but this list of books will push you in the right direction. Next comes practice, practice, practice.