I've uploaded two sets of slides from my presentations at EKON 22 : Object Pascal Clean Code Guidelines Proposal High Performance Object Pascal Code on Servers with the associated source code The WorkShop about "Getting REST with mORMot" has a corresponding new Samples folder in our […]
Tag - interface
2015-11-17
Benefits of interface callbacks instead of class messages
2015-11-17. Open Source › mORMot Framework
If you compare with existing client/server SOA solutions (in Delphi, Java,
C# or even in Go or other frameworks), mORMot's
interface
-based
callback mechanism sounds pretty unique and easy to work with.
Most Events Oriented solutions do use a set of dedicated
messages to propagate the events, with a centralized Message
Bus (like MSMQ or
JMS), or a
P2P/decentralized approach (see e.g. ZeroMQ or NanoMsg). In practice, you are expected to
define one class
per message, the class
fields being
the message values. You would define e.g. one class
to notify a
successful process, and another class
to notify an error. SOA
services would eventually tend to be defined by a huge number of individual
classes, with the temptation of re-using existing classes in several
contexts.
Our interface
-based approach allows to gather all events:
- In a single
interface
type per notification, i.e. probably per service operation; - With one method per event;
- Using method parameters defining the event values.
Since asynchronous notifications are needed most of the time, method
parameters would be one-way, i.e. defined only
as const
- in such case, an evolved algorithm would
transparently gather those outgoing messages, to enhance scalability when
processing such asynchronous events. Blocking request may also be defined
as var/out
, as we will see below, inWorkflow
adaptation.
Behind the scene, the framework would still transmit raw messages over IP
sockets (currently over a
WebSockets connection), like other systems, but events notification would
benefit from using interfaces, on both server and client sides.
We will now see how...
2015-08-15
Breaking Change in mORMot WebSockets binary protocol
2015-08-15. Open Source › mORMot Framework
Among all its means of transmission, our mORMot framework
features
WebSockets, allowing bidirectional communications, and interface-based
callbacks for real time notification of SOA events.
After several months of use in production, we identified some needed changes
for this just emerged feature.
We committed
today a breaking change of the data layout used for our proprietary
WebSockets binary protocol.
From our tests, it would increase the performance and decrease the resource
consumption, especially in case of high number of messages.
2015-05-18
CQRS Persistence Service of any DDD object with mORMot
2015-05-18. Open Source › mORMot Framework
We introduced DDD concepts some time ago, in a series of articles in this blog. At that time, we proposed a simple way of using mORMot types to implement DDD in your applications. But all Domain Entitities being tied to the framework TSQLRecord class did appear as a limitation, breaking the […]
2015-05-03
SOLID Design Principles
2015-05-03. Pascal Programming

I've just updated the documentation part about the SOLID Design
Principles.
The former blog article
(almost 4 years old!) sounds like a bit deprecated now...
This is why I would extract here an updated version of this material.
Ensure you checked the corresponding part of the mORMot documentation, which is the updated reference, and probably the easiest to read - including links to all the other documentation.
The acronym SOLID is derived from the following OOP principles (quoted from the corresponding Wikipedia article):
- Single responsibility principle: the notion that an object should have only a single responsibility;
- Open/closed principle: the notion that "software entities ... should be open for extension, but closed for modification";
- Liskov substitution principle: the notion that "objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program” - also named as "design by contract";
- Interface segregation principle: the notion that "many client specific interfaces are better than one general purpose interface.";
- Dependency inversion principle: the notion that one should "Depend upon Abstractions. Do not depend upon concretions.". Dependency injection is one method of following this principle, which is also called Inversion Of Control (aka IoC).
If you have some programming skills, those principles are general statements you may already found out by yourself. If you start doing serious object-oriented coding, those principles are best-practice guidelines you would gain following.
They certainly help to fight the three main code weaknesses:
- Rigidity: Hard to change something because every change affects too many other parts of the system;
- Fragility: When you make a change, unexpected parts of the system break;
- Immobility: Hard to reuse in another application because it cannot be disentangled from the current application.
2015-04-06
Asynchronous Service - WebSockets, Callbacks and Publish-Subscribe
2015-04-06. Open Source › mORMot Framework

When publishing SOA services, most of them are defined as
stateless, in a typical query/answer pattern - see
Service-Oriented Architecture (SOA).
This fits exactly with the RESTful approach of Client-Server
services via interfaces, as proposed by the framework.
But it may happen that a client application (or service) needs to know the state of a given service. In a pure stateless implementation, it will have to query the server for any state change, i.e. for any pending notification - this is called polling.
Polling may take place for instance:
- When a time consuming work is to be processed on the server side. In this case, the client could not wait for it to be finished, without raising a timeout on the HTTP connection: as a workaround, the client may start the work, then ask for its progress status regularly using a timer and a dedicated method call;
- When an unpredictable event is to be notified from the server side. In this case, the client should ask regularly (using a timer, e.g. every second), for any pending event, then react on purpose.
It may therefore sounds preferred, and in some case necessary, to have the ability to let the server notify one or several clients without any prior query, nor having the requirement of a client-side timer:
- Polling may be pretty resource consuming on both client and server sides, and add some unwanted latency;
- If immediate notification is needed, some kind of "long polling" algorithm may take place, i.e. the server will wait for a long time before returning the notification state if no event did happen: in this case, a dedicated connection is required, in addition to the REST one;
- In an event-driven systems, a lot of messages are sent to the clients: a proper publish/subscribe mechanism is preferred, otherwise the complexity of polling methods may increase and become inefficient and unmaintainable;
- Explicit push notifications may be necessary, e.g. when a lot of potential events, associated with a complex set of parameters, are likely to be sent by the client.
Our mORMot framework is therefore able to easily implement
asynchronous callbacks over WebSockets,
defining the callbacks as interface
parameters in service method
definitions - see
Available types for methods parameters.
Real-Time ORM Master/Slave Replication via WebSockets
2015-04-06. Open Source › mORMot Framework
In a previous
article, we presented how Master/Slave replication may be easily
implemented in mORMot's RESTful ORM.
Do not forget to
visit the corresponding paragraphs of our online documentation, which has
been updated, and is more accurate!
Sometimes, the on-demand synchronization is not enough.
So we have just introduced real-time replication via WebSockets.
For instance, you may need to:
- Synchronize a short list of always evolving items which should be reflected as soon as possible;
- Involve some kind of ACID-like behavior (e.g. handle money!) in your replicated data;
- Replicate not from a GUI application, but from a service, so use of a
TTimer
is not an option; - Combine REST requests (for ORM or services) and master/slave ORM replication on the same wire, e.g. in a multi-threaded application.
In this case, the framework is able to use WebSockets and
asynchronous callbacks to let the master/slave replication - see
Asynchronous callbacks - take place without the need to ask explicitly
for pending data.
You would need to use
TSQLRestServer.RecordVersionSynchronizeMasterStart
,
TSQLRestServer.RecordVersionSynchronizeSlaveStart
and
TSQLRestServer.RecordVersionSynchronizeSlaveStop
methods over the
proper kind of bidirectional connection.
2015-01-10
mORMot under Linux thanks to FPC
2015-01-10. Open Source › mORMot Framework
You can use the FreePascal Compiler (FPC) to compile the mORMot framework source code, targetting Windows and Linux.
Linux is a premium target for cheap and efficient server Hosting. Since mORMot has no dependency, installing a new mORMot server is as easy as copying its executable on a blank Linux host, then run it. No need to install any framework nor runtime. You could even use diverse operating systems (several Linux or Windows Server versions) in your mORMot servers farm, with minimal system requirements, and updates.
We will now see how to write your software with Linux-compiling in mind, and also give some notes about how to install a Linux Virtual Machine with Lazarus on your Windows computer, compiling both FPC and Lazarus from their SVN latest sources!
2014-10-24
MVC/MVVM Web Applications
2014-10-24. Open Source › mORMot Framework
We almost finished implementing a long-standing feature request,
introducing MVC / MVVM for Web Applications (like RubyOnRails) in mORMot.
This is a huge step forward, opening new perspectives not only to our
framework, but for the Delphi community.
In respect to the existing
MVC frameworks for Delphi, our solution is closer to Delphi On Rails (by the
convention-over-configuration
pattern) than the Delphi MVC
Framework or XMM.
The mORMot point of view is unique, and quite powerful,
since it is integrated with other parts of our framework, as its ORM/ODM or interface-based services.
Of course, this is a work in progress, so you are welcome to put your feedback,
patches or new features!
We will now explain how to build a MVC/MVVM web application using
mORMot, starting from the "30
- MVC Server" sample.
First of all,
check the source in our GitHub repository: two .pas
files, and
a set of minimalist Mustache
views.
This little web application publishes a simple BLOG, not fully finished yet
(this is a Sample, remember!).
But you can still execute it in your desktop browser, or any mobile device
(thanks to a simple Bootstrap-based responsive design), and see the
articles list, view one article and its comments, view the author information,
log in and out.
This sample is implemented as such:
MVVM | Source | mORMot |
Model | MVCModel.pas |
TSQLRestServerDB ORM over a SQlite3 database |
View | *.html |
Mustache template engine in the Views sub-folder |
ViewModel | MVCViewModel.pas |
Defined as one IBlogApplication interface |
For the sake of the simplicity, the sample will create some fake data in its own local SQlite3 database, the first time it is executed.
2014-09-13
Some thoughts about "modern" pascal, generics, code and data structures
2014-09-13. Pascal Programming
In a comment of a Google+ announcement about new C# features, Stephan did react about my naive enthusiasm about SmartPascal.
Apart from the fact that he did miss the numerous ways of creating Windows executable in this dialect (I quoted at least 5 diverse ways), he was chocked by the fact that the SmartPascal syntax, in its actual idiom, does not support generics.
But are generics mandatory?
I'm not speaking about any drug identified by its chemical name rather than its
brand name (Wikipedia).
I would neither comment on the current Delphi implementation of generics (which
may appear not so polished, nor very widely used, even in the Delphi RTL/FMX,
but for TList<T> TDictionary<>
).
Just share some thoughts about what is, to my opinion - which may be wrong and
biased! - the most important part of today's programming.
2014-08-05
Returning content as XML
2014-08-05. Open Source › mORMot Framework
By default, interface-based services of a mORMot server will always
return a JSON array (or a JSON object, if
TServiceFactoryServer.ResultAsJSONObject
is
true
).
With some kind of clients (e.g. if they are made by a third party), it could be
useful to return XML content instead.
Your mORMot server is able to let its interface-based services return XML context instead, or in addition to the default JSON format.
2014-07-12
Static class variables are just global variables in disguise
2014-07-12. Pascal Programming
Cape Cod Gunny just wrote a blog article about how to replace a global variable by a static class instance.
But I had to react!
Using such static declaration is just another way of creating a global
variable.
This is just a global variable in disguise.
In fact, the generated asm will be just like a global variable!
It encapsulates the global declaration within a class name space, but it is
still IMHO a very wrong design.
I've seen so many C# or Java code which used such a pattern (there is no global
variable in those languages), and it has the same disadvantages as global
variables.
Just like the singleton
syndrome,
Code is just not re-entrant nor thread-safe.
Nightmare to debug and let evolve.
2014-05-30
Software Design, Brook, mORMot, RAD, SOLID and OOP
2014-05-30. Open Source › mORMot Framework
We got a very instructive
discussion in our forums, with Silvio, the maintainer of the
Brook Framework.
Brook is a nice framework for writing web applications using Free
Pascal.
It comes to my mind what mORMot can offer.
We did not want to compare the features or say that one framework is better
than the other, but it appeared to me that a lot of object pascal programmers
are tied to 20th century programming model.
In fact, to embrace the potentials of mORMot, you need to switch your mind, and enhanced your RAD and OOP background, into 21th century SOLID model.
2014-04-28
Mustache Logic-less templates for Delphi - part 3
2014-04-28. Open Source › Open Source libraries
Mustache is
a well-known logic-less template engine.
There is plenty of Open Source implementations around (including in JavaScript,
which can be very convenient for AJAX applications on client side, for
instance).
For mORMot, we created the first pure Delphi implementation of it,
with a perfect integration with other bricks of the framework.
In last part of this series of blog articles, we will introduce the
Mustache library included within mORMot source code
tree.
You can download this documentation
as one single pdf file.
Mustache Logic-less templates for Delphi - part 2
2014-04-28. Open Source › Open Source libraries
Mustache is a well-known
logic-less template engine.
There is plenty of Open Source implementations around (including in JavaScript,
which can be very convenient for AJAX applications on client side, for
instance).
For mORMot, we created the first pure Delphi implementation of it,
with a perfect integration with other bricks of the framework.
In this second part of this series of blog articles, we will introduce the
Mustache syntax.
You can download this documentation
as one single pdf file.
Mustache Logic-less templates for Delphi - part 1
2014-04-28. Open Source › Open Source libraries
Mustache is a well-known
logic-less template engine.
There is plenty of Open Source implementations around (including in JavaScript,
which can be very convenient for AJAX applications on client side, for
instance).
For mORMot, we created the first pure Delphi implementation of it,
with a perfect integration with other bricks of the framework.
In this first part of this series of blog articles, we will introduce the
Mustache design.
You can download this documentation
as one single pdf file.
2014-04-18
Introducing mORMot's architecture and design principles
2014-04-18. Open Source › mORMot Framework
We have just released a set of slides introducing ORM, SOA, REST, JSON, MVC, MVVM, SOLID, Mocks/Stubs, Domain-Driven Design concepts with Delphi, and showing some sample code using our Open Source mORMot framework. You can follow the public link on Google Drive! This is a great opportunity to […]
2014-04-07
JavaScript support in mORMot via SpiderMonkey
2014-04-07. Open Source › mORMot Framework
As we already
stated, we finished the first step of integration of the
SpiderMonkey engine to our mORMot framework.
Version 1.8.5 of the library is already integrated, and latest official
revision will be soon merged,
thanks to mpv's great contribution.
It can be seen as stable, since it is already used on production site to serve more than
1,000,000 requests per day.
You can now easily uses JavaScript on both client and server side.
On server side, mORMot's implementation offers an unique concept, i.e.
true multi-threading,
which is IMHO a huge enhancement when compared to the regular node.js mono-threaded implementation,
and its callback hell.
In fact, node.js official marketing states its non-blocking scheme is
a plus. It allows to define a HTTP server in a few lines, but huge server
applications need JavaScript experts not to sink into a state a
disgrace.
2013-06-07
Authentication and Authorization
2013-06-07. Open Source › mORMot Framework
Our mORMot framework tries to implement security via:
- Process safety;
- Authentication;
- Authorization.
Process safety is implemented at every n-Tier level:
- Atomicity of the SQLite3 database core;
- RESTful architecture to avoid most synchronization issues;
- ORM associated to the Object pascal strong type syntax;
- Extended test coverage of the framework core.
Authentication allows user identification:
- Build-in optional authentication mechanism, implementing both per-user
sessions and individual REST Query Authentication;
- Authentication groups are used for proper authorization;
- Several authentication schemes, from very secure SHA-256 based challenging to
weak but simple authentication;
- Class-based architecture, allowing custom extension.
Authorization of a given process is based on the group policy,
after proper authentication:
- Per-table access right functionalities built-in at lowest level of
the framework;
- Per-method execution policy for interface-based services;
- General high-level security attributes, for SQL or Service remote
execution.
We will now give general information about both authentication and authorization in the framework.
In particular, authentication is now implemented via a set of classes.
2013-05-11
Delphi XE4 NextGen compiler: using byte instead of ansichar?
2013-05-11. Pascal Programming
When I first read the technical white paper covering all of the language changes in XE4 for mobile development (tied to the new ARM LLVM-based Delphi compiler), I have to confess I was pretty much confused.
Two great mORMot users just asked for XE4/iOS support of mORMot.
Win32/Win64 support for XE4 will be done as soon as we got a copy of
it.
I suspect the code already works, since it was working as expected with XE3,
and we rely on our own set of low-level functions for most internal work.
But iOS-targetting is more complex, due to the NextGen compiler, mainly.
« previous entries - page 1 of 3