What is Domain-Driven Design?

Domain-Driven Design is an approach to software design saying that developers should focus on the domain, by creating a strong model representing this domain and that handles all the domain logic. It was created by Eric Evans and it is presented in the eponymous book, an essential resource to understand all the patterns that characterized Domain-Driven Design (abbreviated as DDD).

These patterns can be separated into three sets:

  • The blocks, explaining the basic objects and elements the developer will have to handle when using DDD.
  • The advanced elements of DDD, offering a Deeper Insight.
  • The concepts for achieving a Strategic Design.

Some of these concepts are ubiquitous: they can be applied to any programming language and / or any software development. However some of them are more specialized, depending on the organization of the project, the teams involved and the different processes. In fact, most of the concepts for achieving Strategic Design (the third set of patterns) are strategies to apply depending of the project context.

This article will not present Domain-Driven Design and how it can help projects become more successful. It will focus on everything specific to Flex development following Domain-Driven Design approach.

Flex and Domain-Driven Design

Flex (and by extend, the Flash platform) is a specialized technology. When you're working on this platform, you usually connect to a server as a client. You also need to be aware of asynchrony, because your application is reachable on the web and the user can access it through different devices (mobile phones, tablets, computers, video game consoles, etc.). You do care of loading time, of the quantity of data to handle and you often ask the question: "should I apply this logic on client-side or server-side?". These are strong constraints forcing developers and architects to adapt. Domain-Driven Design hopefully offers patterns helping your developments in different situations, for example how to work with another system that is sometimes out of control or not part of the same team.

The basic blocks presented in DDD can easily be applied to Flex development: Entities, Value Objects, Services, Factories are concepts and terms already used in many projects. Advanced blocks are also part of every day of a Flex developer, containing patterns like Assertions, Specification, Strategy or the use of Interfaces. Concepts of Strategic Design are really interesting concerning Flex when it comes to a large-scale architecture: there will be many constraints to face and DDD provides different possibilities to achieve efficiency depending on context.

At first sight, DDD seems to apply the same way to Flex as to other technologies. However I think there are some patterns that should be emphasized to Flex developers as they concerns him more directly.

Patterns applied to Flex development

While some basics elements of Domain-Drivne Design like Entities or Services are used the same way as with other technologies, some patterns are particularly interesting to study as they raise and deal with specific constraints in the Flash/Flex context. Let's focus on some of them and remind this list is not exhaustive.

Layered Architecture

In Domain-Driven Design, the Layered Architecture pattern partition the code into four different layers: Presentation, Application, Domain, Infrastructure. The most important part should be the Domain layer, as it is were lies the core of the model, that is to say the core of application. But Flex projects are, by nature, user-interface focused, giving them a strong Presentation layer.

This partition can be considered the same as MVCS (Model View Controller Service), but it is different in the fact that all domain logic should stand in the Domain layer, and not be shared between the Model and Controller part of the MVC pattern. I have worked on projects where some of the domain logic was in the View part, like in a "Code Behind" or a "Presentation Model". Using the Layered Architecture terminology clearly separates domain logic and encapsulates it into a single layer.

It is really interesting to look at how projects / frameworks uses this architecture. Here are two really interesting examples:

Modules

Modules are basic elements of Domain-Driven Design applied to large-scale project. Hopefully, the concept of module is also a primitive in Flex, having native ways to handle them. A module should be treated as a completely independent piece of code, that should have the possibility to be executed alone and have its own test suite.

A Flex module is even more important as he will surely be deployed on the web. Web projects means loading time, and every developer should try to reduce the loading of every application. Flex modules offers the possibility of decoupling your code and at the same time having small pieces of application available separately for the user, that will be loaded "on the fly" only when the user really needs it.

Having this module strategy is then a double advantage: technically (reducing coupling) and for the user, reducing is waiting time.

Ubiquitous Language

Ubiquitous Language is all about communication. Having a shared language between projects participants, but also between different teams. On Flex projects, you will often have many different teams: Flex developers of course, but also server developers (.NET, Java, PHP, etc.), designers, project managers, business analysts, etc. The Flex developer is always in the middle of this workflow: he needs to agree on a contract with the server-side, explains his needs to the designers, listen to the business requirements, etc. That's why he may be the one that needs Ubiquitous Language the most: if he cannot understand and share the key concepts and terms of the domain, he will clearly be confused with one of the actor around him.

Assertions

Assertions is another pattern easily applicable to Flex development. Assertions are tools that will help your code to be stable and so have your domain logic tested. FlexUnit is one of the tools that can be used to ensure that. But other tools can indirectly help assert your code is not broken. Continuous Integration can be achieved with tools like Hudson, offering unit testing reports, FlexPMD reports for code quality, etc. and this done automatically, leaving the developer time to focus on the domain logic instead of testing manually the system.

Limitations

Lately, web technologies evolved so the productivity of web applications increase, offering better tools and less constraints to the developer. As a matter of fact, he can spend more of his time focusing on the domain, instead of some interface problem he encountered before with plain HTML for example. But these technologies still feel the legacy of the web model, some constraints that limits the applications of Domain-Driven Design to Flex development.

Asynchrony

Repositories (a basic DDD pattern) will communicate in an asynchronous way, meaning they must be "aware of this mechanism", having some handlers whenever data is fetched. This is clearly a technical constraint being part of the Domain layer, and though reducing the clarity of it. Using Java, DAO will be used to abstract these operations and hide the way data is fetched, but it is often synchronous operations. What we would like to achieve in Flex is to have this kind of abstraction, hiding implementation detail of this asynchrony to the domain. For example, the Operation API of the Spring ActionScript framework will hide every kind of asynchronous request (remoting, REST, Web service, etc.) behind an interface.

This is one of the constraints for combining Flex and DDD together.

Caching

Sometimes data needed to be cached on client side. It can be context information, some elements related to the current user, etc. All this information should also be available via Repositories, as the purpose of a Repository is to provide access for Aggregates to object instances. Retrieving from a cache or through a distant call is a technical difference that will complicate the implementation of the Repository. Therefore again it is needed to find a convenient way of "hiding" these implementation details out of the domain layer.

Sharing the model with the server

Often in client / server projects, the client will not handle the whole model. For example if the project gather some information from different sources, integrating them on the server side and just passing what to display to the client, it will divide this abstract model in two parts. A Flex module will not handle a complete model but just the information from this model it actually needs to display. Sharing this core data with the server is a key factor for a successful project.

Even if Domain-Driven Design offers Strategic Design patterns to help discussion and communication between different teams holding the domain model, Flex development coupled to a server will raise some difficulties in the fact that you need to chose what information to share to the interface. Also, core logic will need to stay on the server side for performance purpose (think of extracting data from a database and sort it / paginate it using domain data). Working on such an architecture forces the developer to adopt some strategy. Patterns like Shared Kernel or Single Bounded Context are not applicable, limiting the developers to adopt Customer / Supplier Teams or Open Host Service. Off course there is a shared kernel, a core model that you find on both server and client. But because they are coded in different language, they are not synchronized and so need some attention to stay stable.

Having a model focused on what should be displayed and not on the core of the domain may impoverish the model on the client side.

Conclusion

Domain-Driven Design can be applied to Flex projects. The aspect of giving all the effort to the domain model is possible, even if Flex is intrinsically a user interface focused framework. Using some patterns like Layered Architecture or Modules is relevant for Flex development, and clearly give a structure to projects. However, the challenge of applying Domain-Driven Design to Flex resides on the fact that Flex development often involve third-party teams, like a server team and designers. Being this central actor discussing with other people, client developers therefore have the responsibility of using and building the Ubiquitous Language and be proactive to apply patterns like Open Host Service or Customer / Supplier Teams.

Les technologies riches s'activent en ce début d'année 2008 ! Tout d'abord du coté d'Adobe, où après un an d'attente viennent de sortir les versions finales de Flex 3 et AIR. Petit rappel :
  • Flex 3 est la nouvelle version du framework d'Adobe pour développer des applications riches. C'est une solution qui passe en open source pour cette troisième version, mais ce ne sont pas les seuls avantages de cette nouvelle mouture : l'IDE se retrouve renforcé par de nombreux éléments, de nouveaux composants arrivent, les performances sont accrues, etc. Vous pouvez pour plus de détails lire mon article de preview sur Flex 3 ou même le télécharger en version d'essai.
  • AIR fait beaucoup parler de lui. Il s'agit d'un environnement d'exécution multi plate-formes permettant aux développeurs web (Html / Javascript et Flash / Flex) de déployer leurs applications directement sur le bureau, pour ainsi profiter de fonctionnalités avancées telles que l'accès aux ressources locales, un mode déconnecté, une base de données, etc. Depuis la présentation d'Apollo il y a plus d'un an, ce projet était pour moi une grande attente. Si son évolution a présenté de nombreux projets très intéressants, des questions restent en suspens concernant le type d'applications sur lesquelles AIR pourrait faire la différence. Espérons que cette version permettra d'y voir plus clair. N'oubliez pas de mettre à jour vos runtimes AIR !
Du coté de Microsoft, on s'active également. Après les Tech days 2008, on dévoile une partie de Silverlight 2, dont on apprendra certainement plus lors du MIX 08 (à partir du 5 mars). On découvre donc :
  • L'intégration d'un sous-ensemble du framework de WPF : enfin du binding (gros manque de la version 1 je pense), des animations et des thèmes visuels !
  • Des contrôles riches : la panoplie attendue est bien présente : des contrôles simples (RadioButton, CheckBox, etc.) aux conteneurs de données (DataGrid, etc.), tout y est !
  • Une grosse API réseau : avec le support de REST, WS-*, POX, RSS et autres, Silverlight marque des points.
  • Tout un tas de classes évoluées pour manipuler les données, de type XML, tableau, collections etc.
On attaque donc très fort en attendant le MIX et autres réjouissances. Que pensez-vous de ces sorties ? Vont-elles bousculer un peu les idées ou les positions des acteurs du marché ?
Tout développeur sait qu'une bonne documentation est nécessaire pour appréhender, apprendre et approfondir une technologie. On peut aussi penser que la qualité / quantité de livres produits sur une technologie peut être un reflet de son succès. C'est pourquoi je souhaite présenter quelques livres autour de la technologiesAdobe Flex ; notamment car l'offre commence à être intéressante et de plus en plus complète. Petit panorama de quelques livres "références" pour développeurFlex, débutant, initié ou confirmé.

Advanced ActionScript 3 with design patterns

Très intéressant mais également très spécifique, ce livre présente une dizaine de design patterns souvent utilisés dans des applications de type RIA. On y retrouve par exemple les très utilesSingleton, Command, Factory , etc. A conseiller par exemple aux développeurs venants de monde où l'on utilise souvent ces patterns, pour permettre une bonne approche du langageActionscript 3 mais également la mise en application de ces design patterns dans le cadre d'applications Flex . Personnellement, il s'agit de mon préféré : une référence pour toute personne concernée par l'architecture d'une application RIA.

Developing rich clients with Macromedia Flex

Cet ouvrage écrit par Steven Webster et Alistair McLeod (fondateurs de iteration:two, créateurs du framework Cairngorm) fut l'un des premiers sur le sujet : il fut en tout cas le premier à devenir une référence, car il jette les fondements des RIA utilisant la technologie Flex. Bien que cet ouvrage commence à dater (Macromedia ne faisait pas encore partie d'Adobe), il reste très intéressant de part les notions qu'il met en avant, l'interaction et les capacités du Flash Player qu'il souhaite placer comme fondements des RIA développées par la technologie Flex.

Adobe Integrated Runtime (AIR) for Javascript developers : Pocket Reference

Un petit ouvrage très condensé mais très intéressant car focalisé sur les développement Javascript pour AIR. Il s'agit de l'un des premiers ouvrages écrit sur le sujet, par trois gourous d'AIR (Mike Chambers, Daniel Dura et Kevin Hoyt). Le coté très intéressant de ce livre, au delà de son prix raisonnable, est son approche orienté pour les développeurs Web qui n'ont pas forcément de connaissance autour d'actionscript ou de Flex. Au programme : qu'est-ce que AIR ? Comment déployer son application AIR, comment y insérer de l'HTML ? Comment interagir entre AIR et l'HTML ?

Actionscript 3.0 Cookbook

(comme le dessin de rectangle ou de cercle), et d'autres très intéressants pour de mises en pratiques souvent présentes dans le développement de RIA : la gestion de la vidéo, du Ouvrage très complet sur l'actionscript 3, le langage utilisé par Flex 2 mais également Flash 9. Certains éléments du livre peuvent paraître peu utiles pour les flexeursXML, etc. Un très bon ouvrage donc, qui pourra également contenter des designers très portés sur le code.

Flex & AIR

En français, il n'existe à l'heure actuelle qu'un seul ouvrage qui ne soit pas une simple traduction de l'anglais. Il s'agit de Flex & AIR, chez Micro Application. Très récent (sorti ce mois-ci), j'ai pu le feuilleter et ai particulièrement apprécié le fait qu'il soit illustré : en effet, on y retrouve de nombreux exemples concret pour la plupart des chapitres présentés. A la manière de l'Actionscript 3 Cookbook, cet ouvrage parcourera l'ensemble des pratiques courantes autour de Flex de manière brève mais exhaustive. Un ouvrage très complet qui offre également une introduction à AIR et ses principaux fonctionnements, et à un prix raisonnable. Un must-have !

Il existe bien évidemment de nombreuses ressources sur Internet (le site livedocs d'Adobe est une référence), mais l'apport d'un livre papier, consultable partout, était et reste toujours très apprécié. Si vous connaissez ou souhaitez proposer d'autres livres autour de ces technologies, n'hésitez pas à les partager en commentaire !

Actualité RIA

dimanche 2 décembre 2007
Pas mal de nouveautés ces derniers temps sur le domaine des RIA. Voici un peu en vrac certaines des annonces intéressantes de ces derniers jours.

Silverlight 2.0

Microsoft change légèrement sa stratégie : après avoir annoncé Silverlight 1.1 en même que que la 1.0, la prochaine version passera directement au cap suivant, s'appelant donc Silverlight 2.0. Plus de 1.1 donc, mais de nombreuses nouveautés justifiant une release "majeure", cette dernière prévoyant une première bêta pour le 1er quarter 2008, et une version finale pour la seconde moitié de 2008. Quoi de neuf pour Silverlight ? Des nouveautés déjà annoncées comme la gestion du CLR et DLR (voir ma présentation de Silverlight pour plus de détails), mais également une gestion des DRM et des composants d'interfaces bien plus poussés comparé à la version 1.0. Je pense que ce dernier point est très important car il consistait pour de nombreuses personnes ayant testé Silverlight comme l'un des points faibles de la première version. En voyant apparaître le binding de données, l'ensemble des composants "standards" (text box, radio button, etc.), les développeurs auront toutes les cartes en main pour créer de véritables applications. Pour tous les détails, je vous conseille ce très intéressant article de Tim Sneath, évangéliste Microsoft.

Prism sur mac et linux

Prism, le projet très intéressant mené par Mozilla pour déporter des applications web sur le bureau est déjà disponible pour Mac et Linux ! Pas d'attente donc pour un projet qui fait pas mal parler de lui. J'en ai déjà parlé dans mon dernier article, mais Prism est très intéressant dans le sens où, comme le dit Tristan Nitot, c'est un projet dont l'idée de donner un grand coup de pied dans la fourmilière de consultation Internet. Une nouvelle vision de l'accès aux données, pour offrir plus de libertés à l'utilisateur ?

Visual Studio 2008 est sorti

Visual Studio, l'environnement de développement de Microsoft est disponible, avec les outils associés pour développer des applications Silverlight. Pour l'instant rien de neuf mais on nous promettait une intégration de plus en plus proche entre la suite Microsoft Expression (plutôt orienté design), Visual Studio (pour les développeurs donc) et Silverlight / WPF, les plates-formes riches.

Flex Builder gratuit pour les étudiants

Très bonne nouvelle que de voir Adobe offrir Flex 2 aux étudiants et universités qui le souhaitent ! Flex pourrait évidemment devenir un levier important pour approcher des problématiques telles que l'importance de l'interface, du design et de l'ergonomie dans une application Web.

Rechercher