Code Elegance

Contextual Domain Models

One of the most well known enterprise pattern is the Domain Model often used in an Onion architecture or Hexagonal architecture: the DM as the center of our application.

I totally agree with that implementation, but, today, I’m not sure that this center should be one and only one.

The doubt is born during a big refactoring of an application that I’m developing with Alessandro. It is a modular application with a front end that the user use to view and manipulate data and a backend that works on that data.

In our case the DM is unique and shared between the frontend and backend.

The problem is that the properties and methods used by the frontend are not always the same of those used by the backend even if they “work” on the same object. They use a different point of view. This take us to have big classes that do two kind of work (SRP violation?)

The classes of an application are an abstraction of the real domain, this mean that a class will have only some of the characteristics of the real object, it will have only the attributes and operations needed by the application context.

So why should I build a single class for the two purpose?

To push us to a single class is the Database. Often on Db we will have a single table for all the Car information, but…

…the Database is only a storage and the DM should be independent from his persistence representation so that the relation 1 Class <==> 1 Table is not always true.

So I can map a single table on different classes without worrying about the persistence.

Doing this way, I mean splitting the domain model in different sub models, take us to a set of smaller specialized classes independent from the others, that means augmented maintainability and cleaner code.

Udi Dahan talks about this concept here: http://www.infoq.com/presentations/Making-Roles-Explicit-Udi-Dahan

Posted in Emanuele DelBono | No comments

My presentation on Mock Objects (UgiALT.NET Conf)

Here you can find the slides of the presentation that I did last week at the Italian ALT.NET Conference about mock objects: http://www.slideshare.net/emadb/mocking-2998380

(they are in Italian, sorry)

Posted in Emanuele DelBono | No comments

UgiALT.NET V Conference

Last Saturday there was the winter edition of the Italian ALT.NET conference. The 5th edition. It was a great day, with more the 130 participants, 20 sessions about DDD, BDD, TDD, SQL and NO-SQL Database, REST, Dynamic Languages, agility, Refactoring, #Architecture, Mock Objects, HTML5, iPhone, Monotouch, JQuery and many more themes.

One of the aspects that characterize the ALT.NET conference is the high level of the sessions (there was no entry level sessions) and the high level of the attendees. In every session that I followed there were always a discussion on the topic and the speaker leaves the attendees speak and tell their opinion so that everybody can learn from the others. Most discussion has continued in the hall and in the others rooms available for open spaces.

For me, Simone and Claudio it was an hard day dealing with the organization, but most attendees help us when needed, so my thanks goes to all the people that help us yesterday.

Other thanks to the speakers, most of them came from other cities, Hadi and Chris from another country. Thanks for coming.

Finally the donors, this year we collected money from donors that gave us something to cover the costs. It went great. With the donations we cover all the costs and we have more money for the next edition (june? july?).

I’m really happy, in 3 year we built a .NET community that is not tied to the .NET framework but is interested in all the technologies that helps the developer to build better software.

Here are some photos: http://picasaweb.google.com/diegoguidi/Milano23012010

In the next days we will publish the slides and demos from the presentations.

 

Technorati Tags: ,,
Posted in Emanuele DelBono | No comments

Experiments with MongoDb

During the Xmas holidays I found the time to have a look at MongoDb a Document oriented Database where the schema is based on JSON.

I downloaded the binaries and the C# Driver and I started some experiments.

The setup-time is minimal, the server is a console application that remain ready on a certain port:

D:\mongodb-win32-x86_64-1.2.1\bin>mongod.exe --dbpath ./data

Tue Jan 05 19:16:20 Mongo DB : starting : pid = 0 port = 27017 dbpath = ./data m
aster = 0 slave = 0  64-bit
Tue Jan 05 19:16:20 db version v1.2.1, pdfile version 4.5
Tue Jan 05 19:16:20 git version: 45992de574979343f34fdfe96b069d5d1eff0182
Tue Jan 05 19:16:20 sys info: windows (6, 0, 6002, 2, 'Service Pack 2') BOOST_LI
B_VERSION=1_39
Tue Jan 05 19:16:20 waiting for connections on port 27017

Above I simply specified the data folder even if there are a lot of parameters you can set.

The first sample that I write is this:

Mongo mongo = new Mongo();
mongo.Connect();
Database db = mongo.getDB("MyTestDb");
IMongoCollection posts = db.GetCollection("Persons");

Document doc = new Document();
doc["Name"] = "Emanele";
doc["Surname"] = "DelBono";
posts.Insert(doc);


Document example = new Document();
example["Name"] = "Emanuele";
ICursor cursor = posts.Find(example);

foreach (Document document in cursor.Documents)
{
  Console.WriteLine(document.ToString());
}

The first block is needed to open the “connection” to the database and to select with collection to work with.

Then I create a new Document and I fill in the key value pairs. The Document class is a dictionary that keep the document data and in JSON format and is converted BSON by the driver when the insert instruction get called.

The third block is a query to the database. I created a new document with a property name and the needed value, the Find method get a cursor from the database with all the matching document (i.e. all the persons whose name is Emanuele).

The power is in the storage and query method. You can create a complex document (with sub-documents, collection and so on) and store like a simple document.

This is a very first basic example on how to setup and run a micro-application on MongoDb, I’m now working on an extension to transform domain model objects in Document hierarchies so I can avoid the manual mapping from a Person class to the Document class.

Maybe in a next post I’ll talk more about that.

Posted in Emanuele DelBono | 6 comments

Avoid DataGrid*

A lot of software houses are migrating their application to the (new) WPF framework to take advantage of all the new stuff (layout models, controls, templates, styles,…)

WPF leave to the developers the freedom to realize appealing user interfaces that support an alternative interaction model not tied to the old windows controls. The benefits for the end user are countless, more productivity, easier interaction, information “find-ability”, and so on…

But what happens most of the times?

As soon as a new developer opens Visual Studio he asks: “Where’s the DataGrid?”

Why?? Is it possible that the only way that a developer knows to show some data on the screen is to put it in a grid?

I developed a bunch of WPF applications and only in one case I used the DataGrid, I always used ListBoxes, ItemControls, StackPanles….using a template to customize their appearance to show the most important information and to give the user the ability to drill down into the details when needed.

So, please, please, with WPF we have the power in our keyboard don’t use datagrids to show your data, think about your user!

The web is full of examples that don’t use the DataGrid (Google and Amazon for example) so don’t be lazy, take time to design a better user interface!

 

* No datagrid was used to write this post

Posted in Emanuele DelBono | No comments

Agile Testing Days 2010

The call for paper for the AgileTestingDays 2010 is open, you can submit your proposal on the site.
I’m thinking in these days about a session on testing from a developer perspective.

Posted in Emanuele DelBono | No comments

AgileTestingDays…a beautiful experience

The past week, Emanuele and I were in berlin to attend the agile testing days conference.
We made a speech about Continuous Integration, from theory to practice. It was my first “international” speech and it gone quite fine.
In those days I saw and I spoke with a lot of “agile-guru” like Tom and Mary Poppendieck and it was a beautiful experience.
The percept I had is that the rest of Europe is much more advanced than Italy about agile methodologies and theirs adoption.
For example, Sometimes when we go to our customers and suggest some agile practices, they look us in a strange way…I don’t know why? Some other speaker, instead, told me that in UK or in Germany, for example, the adoption of agile methodologies is almost a standard-de-facto and with their customers they speak about user stories or continuous integration in a natural way. I hope it will be like this also in Italy.

In conclusion, many thanks to Jose and all his staff for the great organization and…see you the next year!

Posted in Alessandro Melchiori | 1 comment

Slides and demo of our session

You can get the powerpoint presentation and the demos of our session about Continous Integration at the Agile Testing Days here: link

If you need help or some information on how to use them feel free to contact us!

Posted in Emanuele DelBono | No comments

@Berlin

Finally, we are in Berlin! Emanuele and I arrived yesterday, after a long travel.
It’s very cold: on saturday, I had a t-shirt on, today in Berlin it’s snowing almost.
Yesterday I had a half-marathon with Ema, but the first impact with this city is not so good…maybe for the rain, maybe for the weather or maybe because I woke up 24 hours before.
The conference starts and today is the tutorials-day…it’s a good chanche to finish my demo for wednesday ;-)

Stay tuned!

Posted in Alessandro Melchiori | No comments

Agile testing days…we’re arriving (almost)

This afternoon, Emanuele and I have built the demo for the agile testing days.
Our idea is that to completely (more or less) reproduce the build environment that the team uses all days in our projects. The tasks that we have scheduled are:

- automatic assemblies versioning
- integrating database changes
- build
- running unit tests
- running integration tests
- deploying
- code metrics (and more over) with source monitor, fxcop and simian

The time available is not so much, and we have tried to choose must useful tasks (for us, obviously)
Any other ideas? Suggestions? Tasks that do you want to investigate?

Posted in Alessandro Melchiori | No comments

Next Page »