Modularisation
concepts
Agenda
- modular programming
- key principles
- loose coupling
- proposal
- the future
Definition
Modular programming is a software design technique that emphasizes separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect or "concern" of the desired functionality.
History

Imperative and procedural programming
#include <stdio.h>
float calculateSum(float numbers[], int size) {
float sum = 0.0;
for (int i = 0; i < size; i++)
sum += numbers[i];
return sum;
}
float calculateAverage(float numbers[], int size) {
return calculateSum(numbers, size) / size;
}
int main() {
float data[] = {85.5, 90.0, 76.5, 88.0, 92.0};
int count = sizeof(data) / sizeof(data[0]);
printf("Average = %.2f\n", calculateAverage(data, count));
return 0;
}

Modularisation
- separation of concerns
- information hiding
- tree module structure


Technique:
loose coupling
# api/polygence/todo/services/todo_item.py
from hermes.constants import ProjectStatuses
from hermes.models import Project
from marketplace.models.models import StudentProfile
from polygence.project_request.constants import ProjectTypes
from polygence.todo.models import TodoItem
class TodoItemService:
@classmethod
def create_follow_up_item(cls, user_id: int, completed_item: TodoItem) -> None:
student_profile: StudentProfile = StudentProfile.objects.filter(owner__id=user_id).first()
active_project: Project = student_profile.project_set.filter(status=ProjectStatuses.ACTIVE).last()
if not active_project:
return
if active_project.type == ProjectTypes.FLAGSHIP:
# ...# api/polygence/todo/services/todo_item.py
from hermes.services import ProjectService
from marketplace.services import StudentProfileService
from polygence.project_request.constants import ProjectTypes
from polygence.todo.models import TodoItem
class TodoItemService:
@classmethod
def create_follow_up_item(cls, user_id: int, completed_item: TodoItem) -> None:
student_profile = StudentProfileService.get_by_user_id(user_id)
active_project = ProjectService.get_latest_active_for(student_profile)
if not active_project:
return
if active_project.type == ProjectTypes.FLAGSHIP:
# ...# api/polygence/todo/services/todo_item.py
from hermes.services import ProjectService
from polygence.project_request.constants import ProjectTypes
from polygence.todo.models import TodoItem
class TodoItemService:
@classmethod
def create_follow_up_item(cls, user_id: int, completed_item: TodoItem) -> None:
active_project = ProjectService.get_latest_active_for_user(user_id)
if not active_project:
return
if active_project.type == ProjectTypes.FLAGSHIP:
# ...# api/polygence/todo/services/todo_item.py
from hermes.services import ProjectService
from polygence.todo.constants import TodoItemTypes
from polygence.todo.models import TodoItem
class TodoItemService:
@classmethod
def create_follow_up_item(cls, user_id: int, completed_item: TodoItem) -> None:
has_active_core_project = ProjectService.has_active_core_project(user_id)
if not has_active_core_project:
return
if completed_item.blueprint.type == TodoItemTypes.INTRODUCTION_MESSAGE:
TodoItemService.assign_from_todo_type(user_id, TodoItemTypes.CREATE_SHARED_GOOGLE_DOC)
if completed_item.blueprint.type == TodoItemTypes.CREATE_SHARED_GOOGLE_DOC:
TodoItemService.assign_from_todo_type(user_id, TodoItemTypes.STAR_LINK)
if completed_item.blueprint.type == TodoItemTypes.PROPOSE_FIRST_SESSION:
TodoItemService.assign_from_todo_type(user_id, TodoItemTypes.SUBMIT_MILESTONE)
if completed_item.blueprint.type == TodoItemTypes.SUBMIT_FIRST_SESSION_FEEDBACK:
TodoItemService.assign_from_todo_type(user_id, TodoItemTypes.CHECK_OUT_FIRST_SESSION_RECORDING)
Answer these:
- What is the information we want to hide from other modules?
- How we want to define the interface of the module?
Example
# # api/polygence/mentor/availability/__init__.py
Thanks!
Modularisation
By Róbert Beretka
Modularisation
Presentation for Email Channel Crew about NodeJS project setup with TypeScript and best practices.
- 60