Multi-layered architecture is a software architecture where different product responsibilities are handled by separate layers. The most common layers used are: user interface and presentation layers, application and business layers, infrastructure layer. Each of them might have its own sub-layers.
User interface and presentation layers provide some multi-modal interfaces which allow users to communicate with the designed system using different methods e.g: keyboard and mouse, speech, gestures and others. Please find that this layer might be implemented as a part of a web-service, stand-alone application with or without graphical user interface. Furthermore, multi-layered architecture allows to create presentation layer before others. It might be interesting especially for the people who want to improve a usability, appearance so these parts of the product which often mostly affect customers.
During a project development engineers should provide reliability of implemented system. It is worth to create a solution to automatically validate each module and the whole application. One of the method to taking care about the code are regression tests. Regression testing is a type of software testing that protect our existing code against the errors caused by the patches, enhancements or other changes. One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the same software.
How it works? Please take a look at the picture below. The most simple regression test framework will compare reference file with the current results.
The problem is: how to create reference files? In most case we could use golden reference model – the reference library or create them manually. Sometimes we haven’t got any golden reference model or we don’t know exactly how specific module should work. In that case it should be considered to treat the current result as reference files. Such approach helps us to track results of our system during the implementation and either fix our code or update the reference files.
Today I want to describe a very simple memory allocator – memory pool with fixed block size. Memory allocators are important especially for embedded systems. Such systems often require a memory management module which help to decrease memory fragmentation and provide efficient memory usage.
The idea for a simple memory management module is to allocate memory once and use it frequently. Memory allocation algorithm shouldn’t allocate any memory block outside the pool. It is possible to create more than one memory pool, e.g one memory pool for each queue.
Today, I will show you three, clever macros. Thanks to them we can get rid of several problems. Full code and an example, as usual, are available on CWorking.
First macro: LOG
#define LOG(stream, pattern, params...) fprintf( stream,"%20s:%3u | " pattern "\n", __FILE__, __LINE__, ##params )
#define LOG(stream, dummy, params...)
I recommend to use it especially with the DEBUG_MODE flag connected to the makefile. Thanks to that we could switch off the logger e.g by changing the project build mode from “debug” to “release”. Logger syntax is the same as fprintf, but it prints not only a formatted string, but also a filename and a line number where logger was called. It is very helpful if we want to find a source of a specific log entry. All logs can be gathered in a log file, stdout, stderr etc. thanks to the “stream” variable.
Last time I wrote about an interface in C language. Today, I will describe how to implement an interface in C++.
In C++, like in C, we haven’t got any special keyword for an interface. We create it using an abstract class – class with at least one pure virtual function. Pure virtual function hasn’t got its own definition – implementation. It is only a declaration within the class, like below:
virtual void fun() = 0;
Pure virtual function has to be implemented in a corresponding derived class. It will be checked during the linking process. Typical interface is presented below
Everyone who ever wrote something in C certainly knows that it is a structural language. However not everyone know that object oriented programming in C is possible and quite simple. To start talking about this we need to know what is an interface and how to implement it.
An interface is a set of functions and rules which can be used to communicate with some specified object. An interface may be common for many different modules which have similar functionality. In my opinion, the most important purpose of the interface is a separation between control plane and algorithms. It is not hard to imagine that if we define interfaces for our application we can implement each module separately. The interfaces help team to cooperate and divide their work. Developer, who knows how to use all required modules before their implementation, will be more confident and will make less mistakes. Well organized project gives a greater chance to finish it earlier without sacrificing its quality.