Archive

Archive for the ‘Software architecture’ Category

Round-up of a data centric architecture

April 11th, 2010 Patrick No comments

In my last big project we had to use a data centric architecture. There was a learning curve which architecture was the most appropriate one. The result is visible in the picture bellow:

Architektur

Lets explaining the diagram. The data (or state) is managed by the database layer and the common layer which contains the .Net class DataSet and the DataTables (logic representation of the physical table in the database). This architecture makes use of the patterns Table Module for domain logic and Table Data Gateway for data access logic.

There is no need for DTOs, the state is loaded by the data access layer into the DataSet which is transported through the upper layers. That means, that all layers (except the database layer) know the common layer. Instead of using the DataSet, you could realize that also with POJOs. But that leads in a data centric approach to an anemic domain model.

The domain layer contains the core business logic (domain logic). When you use a data centric architecture, then you couldn’t program in a pure OO-way. All methods have to have a pointer to the data. In this architecture you have possibility to solve that problem: One pointer to the data-structure (here DataSet) and another to the DataRow by a key (for example the primary key). The other possibility is, that you get a DataRow once and pass it around. The problem with this solution is, that you could get a mess with several DataSets.

One important lesson that was learned, was the need of a service layer (Service Layer pattern) which we called use case layer. This layer contains the services, here Controller called. A Controller represents a use case, for example an activity in a workflow process or a simple CRUD window. The responsibility of a Controller is to control and to coordinate what happen in a use case:

  • Prepare initial data structure, load data for combo boxes
  • Coordinates load or validation of data for additional AJAX calls
  • Coordinates the validation of the data structure
  • Delegate the persistence of the data structure

The layers report data source, workflow and remoting (contains facades which realize the Remote Facade pattern) are just technical layers. They don’t contain any relevant logic. They just delegate to the use case layer.

Finally, the two layers report and web represent the user interface. The report layer talks only with the report data source layer and the common layer. The web layer talks only with the remoting and common layer and asynchronous with the workflow layer. As web layer technology we used ASP.Net Web Forms.

Using silos

We used the term silo to define what you have to do to realize a use case. There were two major use cases: Simple CRUD dialog or a workflow activity (which have also a dialog).

The silo for a simple CRUD dialog contains: Code behind, View, Document, Facade Interface, Facade, Use Case Interface and a Controller.

The silo for a workflow activity contains: Code behind, View, Document Facade Interface, Facade, WFModule, Use Case Interface and a Controller.

The big advantage of a silo is, that it is clear what you have to do and where what kind of logic has to be. It is also clear that you shouldn’t reference classes of an other silo. This rule helps to minimize the side effects.

But there is also a disadvantage: A silo generate boilerplate code (Interfaces, WFModule, Facade). This leads to the anti pattern accidental complexity. To reduce this problem, you could use wizards in your IDE or some code generation tools.

Make clear decisions where reuse should happen

The use of silo arise the question where the reuse of logic happens. This was an other important lesson learned. It is important that it is clear where the reuse has to happen. In this architecture it happens in the domain layer with the methods of the BusinessObject and TableModule. Those methods are driven by the domain and have specific names, what simplifies the reuse.

Conclusion

After understanding the architecture, we were quite productive. But I’m still a fan of simple and clean OO architectures, for several reasons: avoid accidental complexity, encapsulation, information hiding or inheritance. Most of those reasons are a problem with this architecture.

A nice side effect of this architecture is a good support for testability. You could set up every state what you want because there is no encapsulation. The problem of dependencies between classes still has to be solve with dependency injection and a mocking framework.

If you use a technical environment which gives you strong instrument for a data centric architecture you should consider to use them. Important for a data centric architecture is that you define rules where you place your logic and where the reuse happens.

  • Share/Bookmark
Categories: Software architecture Tags:

First developer meeting in Bern

January 21st, 2010 Patrick No comments

Today at the Fachhochschule happened the first developer meeting in Bern. The first tasks were the presentation of each participant and to collect the interests to discuss.

entwicklertreffen

After that Florian Kammermann presented his thoughts about software development. He’s highly interested in business oriented software developing. That means for him, that you have to be agile and follow the principles like DRY, separation of concerns, etc.

At the end of his presentation he showed his favoured design patterns strategy pattern and state pattern. He showed the patterns by java examples.

  • Share/Bookmark

When to use stored procedures

May 13th, 2009 Patrick 8 comments

Recently I discussed with a colleague when to use stored procedures. As exptected it was quite a religious conversation. A few days later I found the following screencast:
The Pros and Cons of Stored Procedures

Based on the discussion and the screencast I tried to summarize my Pros and Cons:

Pros

  • Layering
  • Low-level-Security
  • Protect queries from changing data-access technologies (jdbc, hibernate, toplink, dbcommands, linq to sql, entity framework, nhibernate, etc…)
  • Ivory-Tower-Feature: changing database during project does nearly never happen
  • Coarse-grained Interface approach
  • Performance
  • DBA could tune the queries in a procedure
  • From an integration view, logic could be reuse by several applications

Cons

  • If all logic is in the database, there is a danger that the communication is too chatty (to many calls to the database-server), what is too expensive from a performance perspective
  • Security-Chaos (Too much security-rules on different layers)
  • If you are using the database just as an dump datastore
  • Use the database for what it is strong in it (managing data, not logic)
  • Developer has to maintain the logic in two different languages (java or c# and t-sql)
  • Hard to test (slow, friction with current frameworks, anti-pattern for unit-tests (use of a slow infrastructure))
  • Danger of duplicity of logic (in c# and in t-sql)
  • Bad refactoring support
  • DBA could change the logic in a procedure
  • From an integration view, there could be side-effects, if a stored procedure is used by several applications and one application change the logic

Conclusion
And what is the conclusion? Surprise, surprise: It depends. You shouldn’t use stored procedures for anything and you shouldn’t categorically reject them.
I tend to use stored procedures for performance issues and try to avoid to use them to implement business logic.

  • Share/Bookmark

Are 100% code coverage reasonable?

March 2nd, 2009 Patrick No comments

When you use a code coverage tool one of the first question is what is a good code coverage. Recently I listened to different podcasts (stackoverflow, scott hanselman) where they discuss this topic. I wasn’t really surprised that there wasn’t one unique opinion.
One opinion was that 100% is a good number, an other opinion was that for non-failing code it doesn’t make sense to build a test, so 100% isn’t a good number for most of the projects.
The last opinion sounds not that bad, but for which code it doesn’t make sense to build unit tests?
Here is a (not complete) list of code elements for which I wouldn’t build a unit-test:

  • Properties (.Net)
  • Getters (Java)
  • Setters (Java)
  • Primitive Constructors (no chaining, no big logic in it)
  • Services (which just delegate to the business logic)
  • GUI (Views)
  • Data Access (do not test a framework)
  • Services of another component or another application (do not test a library or another application)
  • Any Generated Code (do not test a tool, in this case a code generator)

Is there a code element or type which I forget?

  • Share/Bookmark
Categories: Software architecture, Testing Tags:

Object oriented programming (Part 1)

April 26th, 2007 Patrick No comments

Jonas showed me an interesting link on infoq. Unfortunately, video shows not the hole presentation, but the things which you could learn are very essential for object oriented programming. I decided, that I want to blog more about that.
One of the main principles is the open-close-principle by Bertrand Meyer. But more about that and the others principles in a later post.

  • Share/Bookmark
Categories: Software architecture Tags: