Skip to content

Instantly share code, notes, and snippets.

@fnbk
Last active February 15, 2021 22:15
Show Gist options
  • Save fnbk/53f897a4e3bba4c3280dcfff4f7c0ee3 to your computer and use it in GitHub Desktop.
Save fnbk/53f897a4e3bba4c3280dcfff4f7c0ee3 to your computer and use it in GitHub Desktop.
#
# POMO - Principal of Mutual Oblivion
#
Two modules at the same level of abstraction should not know each other. ("mutual oblivion" - not knowing each other)
It is the independece of parts - no functional units knows another one. They are all completely independent of each other. - Ralf Westphal
Example - muscle movement in human bodies:
A nerve cell does not know anything about a muscle cell and a muscle cell does not know anything about a nerve cell. All they do is follow a simple contract: Acetylcholine (ACh) - one produces ACh as output, the other consumes ACh as input.
The cells forming your body do not know each other. Each cell is independent and does not have a clue what is going on on a higher level.
It is only when integrating these parts, that we get a "controlled" movement. So "control" is a higher level concept of the whole, not of its parts.
Nature follows this simple recipe to produce complex systems that work.
The Unix philosophy follows a similar approach, it emphasizes simple, short, clear, modular, and extensible code and favors composability:
* Write programs that do one thing and do it well.
* Write programs to work together.
#
# Bad Example
#
* CreateJob() knows technical details of ApplyJob (how to build a http request)
* the technical concern of the http request is scattered around in two functions
public void Deploy(string computerName)
{
var job = CreateJob(string computerName);
var success = ApplyJob(job);
}
public Job CreateJob(string computerName)
{
return new Job
{
HttpVerb = "POST",
HttpPath = "/Deployment",
HttpBody = GenerateRequestBody(computerName), // 'string'
};
}
function bool ApplyJob(Job job)
{
if (job.HttpVerb == "POST") {
var url = _serverUrl + job.HttpPath;
var body = job.HttpBody;
}
if (job.HttpVerb == "GET") {
}
}
#
# Good Example
#
* CreateJob() is only concerned about building the Job object and has no clue what is going to happen with this object
public void Deploy(string computerName)
{
var job = CreateJob(string computerName);
var success = ApplyJob(job);
}
public Job CreateJob(string computerName)
{
return new Job
{
Type = TYPE_DEPLOYMENT;
Data = GenerateDeployment(computerName), // 'Deployment' object
};
}
function bool ApplyJob(JobAction job)
{
if (job.Type == TYPE_DEPLOYMENT) {
var url = _serverUrl + "/Deployment";
var httpVerb = "POST";
var body = JsonConvert.SerializeObject(job.Data);
...
}
if (job.Type == TYPE_REMOVE) {
}
}
#
# Exception to the rule
#
* CreateJob() has basic knowledge that ApplyJob() will generate a request (json body)
public void Deploy(string computerName)
{
var job = CreateJob(string computerName);
var success = ApplyJob(job);
}
public Job CreateJob(string computerName)
{
return new Job
{
Type = TYPE_DEPLOYMENT;
Data = GenerateDeployment(computerName), // 'string'
};
}
function bool ApplyJob(JobAction job)
{
if (job.Type == TYPE_DEPLOYMENT) {
var url = _serverUrl + "/Deployment";
var httpVerb = "POST";
var body = job.Data;
...
}
if (job.Type == TYPE_REMOVE) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment