Code Smell 271 - The Hollywood Principle
Don't Call Us, We'll Call You

I’m a senior software engineer loving clean code, and declarative designs. S.O.L.I.D. and agile methodologies fan.
Search for a command to run...
Don't Call Us, We'll Call You

I’m a senior software engineer loving clean code, and declarative designs. S.O.L.I.D. and agile methodologies fan.
No comments yet. Be the first to comment.
In this series, we will see several symptoms and situations that make us doubt the quality of our developments. We will present possible solutions. Most are just clues. They are no hard rules.
Avoid booleans, always
The perfect prompt doesn't instruct the model on what it already knows how to do.

Approve the logic once, then let it run the same way forever.

Different stages need different brains.

One Second Brain doesn't scale past one skull.

Style errors double when nobody enforces them.

TL;DR: The Hollywood Principle promotes loose coupling by inverting control. High-level components decide when and how to use low-level components.
The Hollywood Principle is a software design principle emphasizing loose coupling between components.
High-level components should not directly control the execution flow in low-level components.
Low-level components should register themselves with high-level components, and high-level components should decide when and how to use them.
This is also known as Inversion of Control.
class TicketCart {
private paymentMethod: PaymentMethod;
constructor(paymentMethodType: string) {
// TicketCart is tightly coupled
// to specific payment method classes
// like CreditCardProcessor and CryptoService.
if (paymentMethodType === 'creditCard') {
this.paymentMethod = new CreditCardProcessor();
} else if (paymentMethodType === 'Crypto') {
this.paymentMethod = new CryptoService();
} else {
throw new Error('Invalid payment method');
}
}
checkout(money: Money): void {
this.paymentMethod.pay(money);
}
}
const cart = new TicketCart('creditCard');
const money = new Money(126, 'USD');
cart.checkout(money);
interface PaymentMethod {
pay(total: Money): void;
}
class TicketCart {
private paymentMethod: PaymentMethod;
constructor(paymentMethod: PaymentMethod) {
// This solution is more open and less coupled
// because it relies on abstractions
this.paymentMethod = paymentMethod;
}
checkout(total: Money): void {
this.paymentMethod.pay(total);
}
}
class CreditCardProcessor implements PaymentMethod {
pay(total: Money): void {
console.log(`Processing payment of ${total.Amount()}
${total.currency()} using credit card.`);
}
}
const creditCardProcessor = new CreditCardProcessor();
const cart = new TicketCart(creditCardProcessor);
const total = new Money(126, 'USD');
cart.checkout(total);
[X] Manual
This is a design smell
[X ] Intermediate
AI generators can sometimes create code that violates the Hollywood Principle if you don't explicitly instruct them to follow inversion of control patterns.
They often generate straightforward, tightly coupled code by default.
AI tools can effectively detect violations of the Hollywood Principle by analyzing code dependencies and identifying tight coupling with proper instructions. (see below).
Remember: AI Assistants make lots of mistakes
| Without Proper Instructions | With Specific Instructions |
| ChatGPT | ChatGPT |
| Claude | Claude |
| Perplexity | Perplexity |
| Copilot | Copilot |
| Gemini | Gemini |
This principle can improve your code quality, reduce complexity, and enhance testability.
Code Smells are my opinion.
"Dependency Injection is fundamentally about passing dependencies to objects, rather than having objects create or find them."
Martin Fowler
This article is part of the CodeSmell Series.