/** * Strategy Pattern Implementation for Order Processing * * The Strategy pattern allows defining a family of algorithms, encapsulating each one, * and making them interchangeable. This refactoring replaces conditional logic with * polymorphic behavior. */ type OrderType = 'digital' | 'physical' | 'subscription'; interface Order { type: OrderType; status?: string; [key: string]: any; } /** * OrderProcessingStrategy defines the contract for all order processing strategies. * Each concrete strategy implements the process method according to its specific logic. */ interface OrderProcessingStrategy { process(order: Order): Order; } /** * DigitalOrderStrategy handles digital product orders. * Digital orders are immediately delivered upon processing. */ declare class DigitalOrderStrategy implements OrderProcessingStrategy { process(order: Order): Order; } /** * PhysicalOrderStrategy handles physical product orders. * Physical orders require shipping and physical delivery. */ declare class PhysicalOrderStrategy implements OrderProcessingStrategy { process(order: Order): Order; private estimateDelivery; } /** * SubscriptionOrderStrategy handles subscription orders. * Subscriptions activate immediately and require ongoing billing. */ declare class SubscriptionOrderStrategy implements OrderProcessingStrategy { process(order: Order): Order; private calculateNextBilling; } /** * OrderProcessor acts as the context that uses strategies to process orders. * It maintains a strategy registry and delegates order processing to the appropriate strategy. */ declare class OrderProcessor { private strategies; constructor(); /** * Process an order using the appropriate strategy based on its type. * @param order The order to process * @returns The processed order with status and additional metadata * @throws Error if no strategy is found for the order type */ processOrder(order: Order): Order; /** * Register a custom strategy for a specific order type. * This allows extending the processor with new order types at runtime. * @param orderType The order type this strategy handles * @param strategy The strategy to register */ registerStrategy(orderType: string, strategy: OrderProcessingStrategy): void; /** * Get all registered order types. * @returns Array of supported order types */ getSupportedOrderTypes(): OrderType[]; } export { Order, OrderType, OrderProcessingStrategy, DigitalOrderStrategy, PhysicalOrderStrategy, SubscriptionOrderStrategy, OrderProcessor }; //# sourceMappingURL=order-processor-strategy.d.ts.map