Is business logic hiding in your data?

Databases are for data. Business logic is usually best stored in readable code. The main reason that it is not a good idea to store business logic in the database is that databases resist change, and business logic changes all the time. A good programming language coupled with a well-engineered application design allows a lot of flexibility for that change to happen on top of the database.

56021_peek-window_sm Continue reading “Is business logic hiding in your data?”

Builder (97) Design Pattern, Part 3

Catching up
Builder (97) Design Pattern, Part 1 has an introduction to the “Gang of Four” Design Patterns book and gives an example where the builder pattern may be useful. Builder (97) Design Pattern, Part 2 talks more in-depth about different ways to approach a common problem in web development, form validation, and ends with a wish for client code that looks a particular way. Namely:

Continue reading “Builder (97) Design Pattern, Part 3”

Builder (97) Design Pattern, Part 2

Builder (97) Design Pattern, Part 1 has an introduction to the “Gang of Four” Design Patterns book and gives an example where the builder pattern may be useful. Where I left off, we have a code snippet like this where the “Validator” class and its associated methods (setRequiredFields and validate) don’t yet exist.

The context around this is that we need a flexible way to validate the form. Continue reading “Builder (97) Design Pattern, Part 2”

Builder (97) Design Pattern, Part 1

Design Patterns by Gamma, Helm, Johnson, and Vlissides could possibly be the “holy grail” of software development books. Most practitioners of the software craft have read it and a good many have it sitting on their bookshelves. It has even spawned the “rock star” t-shirt seen here. Robert C. Martin has talked about it, and so has Martin Fowler, Joshua Bloch, Grady Booch, and many others.

Of the design patterns, I would guess that Singleton (127) or Abstract Factory (87) are the most widely used. Perhaps Strategy (315) is also in there somewhere. Not far behind, I would think, is Builder (97). Yet I would argue that Builder (97) is still an underused pattern. I see a lot of code around that would benefit from Builder (97).

By the way, for those of you wondering, yes that is the way these design patterns are commonly notated. The parenthetical number is the page in Design Patterns where the pattern can be found! Builder (97) means the builder pattern, found on page 97 of Design Patterns.

A quick, easy, and widely applicable example of when to use the builder pattern in web development is in form validation. Fair warning, though! It is going to take some time to get around to demonstrating the need for the builder pattern in this example. Read on and we’ll get there, eventually!
Continue reading “Builder (97) Design Pattern, Part 1”