Organising Domain Logic

ODL

Every software has some business logic. It is easy to talk about business logic but hard to define what exactly it is. Presentation is easy to explain, that is that’s where you view is. And the database is easy, that’s where your data persistence is. It is this middle thing that is a little hard to define. And it is the topic of my latest lecture in by Design and implementation of software course, Organising Domain Logic.

In the lecture I look at ways in which we can organize the this middle layer, where this “business logic” is. The trick question is this: how do you define “business logic”? In fact, the very term does not sound right since business is anything but logical. Having worked in business for many years, logic is not what comes to mind. A clever software programmer might be able to figure everything out, only to get a feature request that completely violates everything about the design.

Since business logic is misleading we will use the term domain logic. A domain is the area of expertice you are working in. If you application is a real estatate property web site, your domain is houses, number of rooms, type of houses, attributes such as gargae, one door or two, swimming pool in the garden and so on. Then there is logic such as viewing property, asking for information, contacting the real estate agent, requesting a visit and so on. If you domain is cars, it’s all about engines, milage, number of doors, and many interesting things about cars.

One way to organize systems in general is to use layering. This is the oldest trick in the book, divide and conquer. With layering each layer has a precise and well defined role. You can ignore everything else, just focus on the logic in the layer. There are three principal layers in any software systems: presentation layer, domain layer and data source layer. You can have more, depending on the system but these three that are universally used, even if the lines are blurry.

I present three design patterns from the textbook (Patterns of Enterprise Applications) that help us organise the domain layer. First, and the simplest is to view your domain as a set of procedures that handle each business transaction is the system. This pattern is know as Transaction Script. You create a script for each request of the presentation that will take care of the transaction performed. The second one is Domain Model. In this the focus is on building a set of classes that represents your domain. Here the focus is on designing a object representation that solves the domain problem. This way is much more flexible that scripts, but introduces some complexities. This works well if the problem begin solves is difficult and building an object graph is need. To give access to the domain model, a Service Layer, may be applied. The third is Table Module, where a class is representing a table or set of tables in the database. Each class will have all the domain logic relating to the data. This works well if the domain problems are centred on the data and support for manipulating the data is good.

In the lecture we also create simplistic Domain Model example, and build a movie database. But of course.

Lecture: Organising Domain Logic

L06 Process Design

ProcessDesign

Processes are programs that run in data centers and have the role of executing specific tasks. They can be scheduled, triggered by an event or run manually. These programs handle task such as importing and exporting, reconciliation, daily updates and calculations and thing like that. Processes usually have no user interface except they log their progress to a log file.

In this lecture we create a process framework based on some of the design patterns we have covered. The idea is that this framework can be used to build processes, and as an example we create process call Import Content Process that reads RSS entries form a new site.

We also look briefly at XML.

Cover picture above is from: Natesh Ramasamy
Mandargiri Hills, Bangalore, India

Slides:

Video:

Part 2:

Part 3:

Part 4:

Part 5:

Part 6:

 

L05 Frameworks

Frameworks

Frameworks are general code libraries that developers use to build their software on. Frameworks are usually specific to a domain, like web frameworks or database frameworks. The benefit of frameworks is the productivity that they provide. With the right framework we can avoid writing low-level functionality and instead focus on our domain problems we need to solve. Frameworks are building blocks and should be used as such, if you have a bad framework or need to invest too much into using the framework, the gains are counter productive.

It may be a good strategy to write your own framework, and in the lecture we look at design patterns that are useful in creating frameworks. We will also look at the Spring framework that is a good example of a well design framework.

Cover image by Javier Corbo
http://www.flickr.com/photos/javiercorbo/

Slides:

Video:

Part 2:

Part 3:

Part 4: