Software Cells #2: Basic structures
In my last posting I introduced the term Software Cell to describe a software application. The minimally necessary ingrediences - a Host and my code to solve a problem (logic) - just looked like an organic cell once I drew some pictures of applications consisting of a Host EXE that contains some assemblies.
In this posting I want to drill down into the details of a software cell. Like organic cells it has a structure: A software cell has to deal with the outside world and I find it benefical to extract the necessary functionality for communication from the core. It´s a separation of concerns.
If an application is not selfsufficient but needs to get information from the outside world - or serves other applications as an information source -, then it needs structures to connect with or to be connected thru.
There are two categories of basic communication structures: Adapters and Portals.
Adapters reach out to other information sources/sinks, and adapt their interfaces to the needs of the core. The Core does not want to concern itself with the details of communication. It wants to live in its world of domain concepts and is shielded from the rough outside world by the adapters, who translate its requests to whatever the communication partners require.
Since there exist at least two general kinds of information sinks/sources, they are matched by two kinds of adapters:
A Resource Adapter connects to a "low level" data resource like a database or a FTP server or the file system. The abstraction level of the resource´s API is low compared to the level of the Core, there is quite an impedance mismatch to overcome. A Resource Adapter thus needs to do some "heavy lifting" in terms of adapting the low level data structures/operations of the resource (e.g. tables, rows or lines in text files) to the needs of the Core (e.g. Customer objects, SMS messages). (Although I used the common database barrell as a picture for a resource it´s perfectly ok to think of a resource as an application of itself. Unless however I write code to be hosted in the resource´s Host, I would not draw a triangle for it.)
An Application Adapter on the other hand connects to another application by a much higher level interface. Whether that´s a Web service or some other means is not important, though. The distinguishing characteristic of an Application Adapter as opposed to a Resource Adapter is the smaller (or even non-existing) impedance mismatch between the data model of the communication partner and the Core. If an Adapter does not need to do "heavy lifting" in order to connect the application to the outside world, I consider it an Application Adapter.
With both adapters the control flows from Core to the outside world.
Each Software Cell can contain an arbitrary number of adapters of both kinds.
If the outside world wants to use services of the Core, however, it needs to go through an Application Portal. The portal provides an interface of some kind thru which operations can be initiated and data can passed to the application. Control flow is from the outside into the application. Whether the portal is implemented as a SOAP Web service or as a custom protocol on top of TCP/IP is not important. The portal just defines some communication endpoint to connect to.
Of course each Software Cell can contain an arbitrary number of portals.
Now, after code for communication has been extracted from the core, what remains in the Core? The Core contains only code necessary for solving the problem. Call this logic or domain logic or business logic or whatever. For calculating prime numbers this could be just one method implementing Erathostenes´ sieve. That´s all. But it also could be many assemblies all working in concert to do some complex data analysis. The Core´s task is to do the problem solving, nothing more, nothing less. And when it needs to access outside information, it uses adapters. In turn, if the Core´s work is to help other applications, it is sent requests thru a portal.
For me it´s very important to distinguish the Core´s functionality from data access and data presentation. In essence, an applicaton should be able to do it´s work without any user interface. (Yes, even a highly visual game.) My recommendation is to design the "blind" Core of an application first without thinking of specific presentation requirements and the details of information access. Later on you can worry about all that, but don´t let uncertainities about a datagrid or database API distract you from your real business: solving a domain problem. Adapters, portals and even the user interface thus are more or less "infrastructure". And we all don´t want to waste too much time working on infrastructure; we´ve more important things to do ;-) (Yes, I know somebody has to position those text boxes and read the data from the database. I´m just trying to say, most of the time that´s not really the important stuff.)
Since I have mentioned the user interface what about it? Where does it fit into the Software Cell picture? I think, it should be another structure within the Cell:
The user interface is implemented by the User Portal. The User Portal is a portal, because again, control is flowing towards the core. The user controls the operations of the core by clicking buttons and menu items and entering data. But since it´s a less uni-directional communication than thru an Application Portal and (often) has to do with visualization, I used a pentagon as the shape for the User Portal to distinguish it from the Application Portal.
To finish off let me show you a couple of drawings for common Solutions:
(Please excuse me leaving the little lines with arrows out for the moment. I guess the informaiton flow is obvious.)
To me these little drawings are quite easy to understand. The clearly show the boundaries of each application and they show how much work has to go into "communication infrastructure" in each application, i.e. which adapters and portals are needed.
What´s left now? We need to talk about the substructures of adapters and portals. We need to talk about interfaces. And we need to talk about the "inter software celluar space". And, yes, I guess I need to say a couple of words about why I think this kind of model is valuable even though we have layered architectures and onions and fiefdoms.