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


























