Skip to content
Programming Fundamentals, OOP, and Architecture Patterns

31 May 2026

Programming Fundamentals, OOP, and Architecture Patterns

Core programming concepts, object-oriented programming, advanced Python features, and the most used software architecture patterns.

Software Python
OOP Architecture Design Patterns

A quick reference of the most important programming concepts, from basics to architecture patterns.

Core Programming Concepts

Variables and Types

name = "Alice"        # string
age = 30              # integer
price = 19.99         # float
active = True         # boolean
items = [1, 2, 3]     # list
config = {"key": "v"} # dictionary

Control Flow

# Conditionals
if age >= 18:
    print("adult")
elif age >= 13:
    print("teenager")
else:
    print("child")

# Loops
for item in items:
    print(item)

while active:
    process()

Functions

def calculate_total(price, tax_rate=0.21):
    return price * (1 + tax_rate)

Object-Oriented Programming (OOP)

The Four Pillars

PillarWhat It Does
EncapsulationHide internal details, expose a clean interface
AbstractionSimplify complex systems by showing only what matters
InheritanceCreate new classes from existing ones
PolymorphismSame interface, different behavior

Example

from abc import ABC, abstractmethod

# Abstraction
class Shape(ABC):
    @abstractmethod
    def area(self):
        pass

# Inheritance
class Circle(Shape):
    def __init__(self, radius):
        self._radius = radius  # Encapsulation

    def area(self):  # Polymorphism
        return 3.14159 * self._radius ** 2

class Rectangle(Shape):
    def __init__(self, width, height):
        self._width = width
        self._height = height

    def area(self):  # Polymorphism
        return self._width * self._height

# Same interface, different behavior
shapes = [Circle(5), Rectangle(4, 6)]
for shape in shapes:
    print(shape.area())

SOLID Principles

PrincipleMeaning
S — Single ResponsibilityA class does one thing
O — Open/ClosedOpen for extension, closed for modification
L — Liskov SubstitutionSubclasses can replace parent classes
I — Interface SegregationMany small interfaces > one big interface
D — Dependency InversionDepend on abstractions, not concrete classes

Advanced Python Features

Decorators

Functions that modify other functions:

def log_call(func):
    def wrapper(*args, **kwargs):
        print(f"Calling {func.__name__}")
        result = func(*args, **kwargs)
        print(f"Done: {result}")
        return result
    return wrapper

@log_call
def add(a, b):
    return a + b

add(2, 3)  # prints: Calling add → Done: 5

Generators

Produce values one at a time (memory efficient):

def fibonacci(n):
    a, b = 0, 1
    for _ in range(n):
        yield a
        a, b = b, a + b

for num in fibonacci(10):
    print(num)  # 0, 1, 1, 2, 3, 5, 8, 13, 21, 34

Context Managers

# Automatic resource cleanup
with open("file.txt", "r") as f:
    content = f.read()
# File is automatically closed

List Comprehensions

squares = [x**2 for x in range(10)]
evens = [x for x in range(20) if x % 2 == 0]

Software Architecture Patterns

Monolithic

All code in one deployable unit.

┌──────────────────────┐
│     Monolith         │
│  ┌────┐ ┌────┐ ┌───┐│
│  │ UI │ │API │ │DB ││
│  └────┘ └────┘ └───┘│
└──────────────────────┘

Good for: Small teams, simple apps, MVPs.

Microservices

Split into small, independent services.

┌──────┐  ┌──────┐  ┌──────┐
│Users │  │Orders│  │Payment│
│ API  │  │ API  │  │  API  │
│ DB   │  │ DB   │  │  DB   │
└──────┘  └──────┘  └──────┘

Good for: Large teams, complex domains, independent scaling.

Event-Driven

Services communicate through events.

Producer → Event Bus → Consumer A
                    → Consumer B
                    → Consumer C

Good for: Decoupled systems, real-time processing.

Layered (N-Tier)

┌─────────────────┐
│  Presentation   │  ← UI / API
├─────────────────┤
│    Business     │  ← Logic / Rules
├─────────────────┤
│  Data Access    │  ← Repositories
├─────────────────┤
│    Database     │  ← Storage
└─────────────────┘

Hexagonal (Ports & Adapters)

           ┌──────────────┐
  REST ──→ │              │ ──→ PostgreSQL
           │   Domain     │
  CLI  ──→ │   Logic      │ ──→ S3
           │              │
 Tests ──→ │              │ ──→ Mock DB
           └──────────────┘

Core logic is independent of external systems.

CQRS (Command Query Responsibility Segregation)

Write ──→ Command Model ──→ Write DB
Read  ──→ Query Model   ──→ Read DB (optimized)

Separate the read and write models for different optimization.

Summary

ConceptWhen to Use
OOPStructure complex code with clear responsibilities
SOLIDGuide class and module design
DecoratorsCross-cutting concerns (logging, auth, caching)
GeneratorsProcess large datasets without loading all in memory
MonolithStart simple, small team
MicroservicesComplex domain, multiple teams
Event-DrivenDecoupled, async workflows
HexagonalTestable, framework-independent core