Originally posted on my personal blog thekraken.org.
In the beginning, when I was learning about software architecture(basically, I wanted to avoid the big ball of mud anti-pattern), I suffered to understand how the Hexagonal Architecture works until one idea came to my mind. The idea was to compare the Hexagonal Architecture with my PlayStation 4. Yes, that was the idea; let me explain it a little more.
The PlayStation 4 is the core of the system. You can connect some accessories to its ports; these accessories work mainly to input or output data from and to the console. For example, to input data, you connect a remote control using the USB input or via Bluetooth; to output data, you connect a Television. No matter which remote control or television is connected to the console as long as they are compatible with it. Even the games are only data input, that is why you can use the console to play many different games.
Well, at this point, maybe you are wondering yourself; what does my PlayStation 4 have to do with software architecture? Yes, I know it sounds out of place, but these are the lessons that I learned from the idea:
1.- Every application should have a core component. The core component should have the business rules of the system and some ports(or at least some mechanism that works similarly) to be able to connect the accessories to the core component. Is it sounds like a PlayStation 4, isn’t it?
2.- The database is an accessory. Use MariaDB, PostgreSQL, a file; it does not matter because your core component should work with all of them as long as there is an interface to connect them to the correct port. I like to compare the database with the game disks or the games stored in the hard drive of the console. The PlayStation 4 works with all of them.
3.- The device to output the data is an accessory. It does not matter if the output is a printed document, another system, a PC monitor, or a cellphone. The PlayStation 4 works with any modern television, or even an old television using some adapter.
4.- The device to input data is an accessory. The core component should work in an API Rest, in a console application, or a desktop application with GUI. The PlayStation 4 works with many different types of remote controls.
Some of the benefits of building software using this technique are:
1.- The core component is easily testable. For example, it is not needed to use the same database as in production, or even also the same input or output devices. The PlayStation 4 can work with no remote control, television, or game. It is not the best-case scenario, but at least you know the main component is working.
2.- In case the database becomes obsolete could be replaced by the new trendy database technology without introducing changes to the core component. What does usually happens when you buy a PlayStation 4? Well, in my case I replaced my old television with a new 55″ television. So I replaced my old obsolete television with a new one, and my PlayStation 4 is still working without any problems on my new television.
3.- The core component is independent of the UI. Yes, the UI could be replaced by a console application without affecting the core component. Thank God I don’t need to buy a new PlayStation 4 for every game that I want to play.
Final notes
It is essential to separate the details of the system(the database, UI, and any other detail) from the business rules of the system. Additionally, the business rules should not depend on the details in any way.
Top comments (0)