liveBook · Manning

Class

As explained in Grokking Software Architecture

A programming construct that defines the properties and behavior shared by its object instances.

A class is a focused unit for organizing behavior. Objects carry data and behavior; classes can define generic types for related objects. section 3.5.3 section 3.8

A changing hospital

Simula modeled patients and treatment rooms as objects and classes. A generic TreatmentRoom could handle different patient types, including a new EmergencyPatient type, without changing its own code. section 3.8

Listing 3.14 “After” - Individual Service Classes
// Handles only validation logic
class OrderValidator {
    validate(order) {
        console.log("Validating order...");
        if (order.items.length === 0 || order.total <= 0) {
            throw new Error("Order is invalid.");
        }
    }
}
 
// Handles only payment processing
class PaymentService {
    processPayment(order) {
        console.log(`Processing payment for ${order.total.toFixed(2)}`);
        // Real payment gateway logic would go here
        return true;
    }
}
 
// Handles only inventory updates
class InventoryManager {
    updateInventory(order) {
        console.log("Updating inventory...");
        // Real database logic to update stock would go here
    }
}
 
// Handles only sending notifications
class NotificationService {
    sendConfirmationEmail(order) {
        console.log(`Sending confirmation to ${order.customerEmail}`);
        // Real email sending logic would go here
    }
}

See focused service classes for order validation, payment, inventory, and notifications. section 3.5.3

How Grokking Software Architecture covers it

How deep it goes
Shows practical service-class examples and historical context, but does not explain class internals.
Examples
Uses order-processing services and a hospital simulation with patient types and a generic treatment room.
What you can do after
Build it from scratch by splitting order processing into focused service classes coordinated by OrderService.
How it connects
Connects classes with objects, inheritance, virtual methods, polymorphism, separation of concerns, and the Open/Closed Principle.

Also explained in

Compare how 27 books explain class →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.