Mafia — An Object Oriented Design

The Godfather is one of the very first novels I properly made the effort to read. It was also my introduction to American Mafia and it’s prevalence during the early 20th century.
The American Mafia, commonly referred to in North America as “the Mafia” or sometimes “the Mob”, or the Italian-American Mafia, is a highly organised Italian-American criminal society and criminal organisation.
Ever since, I have pretty much watched all the mafia movies ever made. So hypothetically, if I were to create a crime family, I’d go about it the object oriented way.
Let’s get crackin’
The American Mafia operates on a strict hierarchical structure.

When a boss makes a decision, he never issues orders directly to workers who would carry it out, but instead passes instructions down through the chain of command. This way, the higher levels of the organisation stay protected from law enforcement if the lower level members who actually commit the crime
are captured or investigated, providing plausible deniability.
Hierarchical Structure
- Godfather (Boss) — He is the head of the family, receives a cut of every operation.
- Underboss — Second in command of the family, first in line to become acting boss if the boss is imprisoned/dead, ensures collection of profits from criminal enterprises, gets a percentage of the family’s income from the boss’s cut.
- Consigliere —Advisor to the family, serves as a representative for the family in meetings with other families, rival criminal organisations, and important business associates.
- Caporegime — In charge of a crew, a group of soldiers who report directly to him, is responsible for any tasks assigned, including murder.
- Soldier — Main workers of the family, usually committing crimes like assault, murder, extortion, intimidation, etc.
Based on this structure of the system, we can incorporate the Chain of Responsibility design pattern
Chain of Responsibility Design Pattern
Chain of Responsibility is a behavioural design pattern that lets you pass requests along a chain of handlers. Upon receiving a request, each handler decides either to process the request or to pass it to the next handler in the chain.

- Handler declares the interface, common for all concrete handlers. It contains two methods, one for handling requests and another for setting the next handler on the chain
- Base Handler has code that’s common to all handler classes
- Concrete Handlers contain the actual code for processing requests. Upon receiving a request, each handler must decide whether to process it and, additionally, whether to pass it along the chain
Classes and Objects
The classes for our design will be:
- Handler — The interface
- MafiaHandler — Base handler
- Classes for concrete handlers — Godfather, Underboss, Consigliere, Caporegime, Soldier

The Code
Classes to represent the handler interface and base MafiaHandler
Concrete handler classes for various handlers in the hierarchy to serve requests
This is how this system will function
# Create a handler instances
godfather = Godfather.new
underboss = Underboss.new
consigliere = Consigliere.new
caporegime = Caporegime.new
soldier = Soldier.new# Create the chain of responsibility
godfather.
next_handler(underboss).
next_handler(consigliere).
next_handler(caporegime).
next_handler(soldier)underboss.handle(:recruit_soldier)
# => Caporegime recruits a soldiergodfather.handle(:attend_meeting)
# => "Consigliere represents the Godfather at meeting with another Mafia family"