deft/journal/2021-06-06--13-43-12Z--service_oriented_programming.org
2021-06-08 00:58:17 +02:00

62 lines
1.6 KiB
Org Mode

#+TITLE: Service Oriented Programming
#+Author: Yann Esposito
#+Date: [2021-06-06]
- tags :: [[file:2020-06-03--19-49-30Z--programming.org][programming]] [[file:2021-03-20--17-27-46Z--architecture.org][architecture]]
- source ::
This is a presentation of a design pattern to architecture a big code
source.
As most programming architecture, the goal is to optimize modularity.
First, this focus on functions.
There will be no global variable.
There are two kind of functions in programming, pure and impure functions.
From a high level perspective:
- =lib/= contain pure functions
- =services/= contain all services
The services directory will contain "sub-project"/"modules".
Every service should have the following structure:
- =src/=
+ =service= the service declaration
+ =core= the implementation of the function in the service, should
contain pure functions
+ =schemas/types= the metas structures (data format mostly)
+ =routes= if you service is a web service, routes declarations
- =test/=
+ =service_test= the service test
+ =core_test= the tests for pure functions
A service should be considered as a function returning a record of functions.
#+begin_src
foo-service-methods
foo-do-a
foo-do-b
foo-do-c
def foo-service
create-service( config-service, bar-service, baz-service)
#+end_src
The component will form an acyclic graph of dependencies.
Principles:
A service contain an internal state.
Every method of the service can access this internal state.
No OOP is needed, only functions.
Ability to test isolated.
You can write:
#+begin_src
with-services-and-conf services conf
test-the-services
#+end_src