Use Strategy when your code performs one stable operation and you need to swap which implementation carries it out. Use Adapter when a collaborator exists but its interface differs from the one your code expects. In short, a Strategy selects or encapsulates behavior, and an Adapter translates a contract. If a small function or a direct call already makes the design obvious, you do not need either pattern.
Both names come from Design Patterns: Elements of Reusable Object-Oriented Software (1995) by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, which catalogs 23 core object-oriented patterns. That catalog is a historical reference. It does not show that either pattern is more common or more effective than a plain function.
As an Amazon Associate I earn from qualifying purchases.
Strategy: varying behavior behind a stable call
The Strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. That is the wording of the glossary definition. The Project Management Institute’s Disciplined Agile strategy pattern reference, as excerpted in search results, describes the same motivation in terms of consumers: a single behavior has varying implementations, and the consumers should be decoupled from any particular one.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchA function-based shape
In JavaScript, the simplest Strategy is a set of functions that share a signature. The caller passes one in and never needs to know how it works. The following example is an illustrative sketch written for this article, not code taken from a source:
#1 Best Overall
const pricingStrategies = {
standard: (subtotal) => subtotal,
member: (subtotal) => subtotal * 0.9,
seasonal: (subtotal) => subtotal * 0.8,
};
function totalFor(subtotal, strategy) {
return strategy(subtotal);
}
const total = totalFor(100, pricingStrategies.member); // 90
The operation, totalFor, stays fixed. Only the rule changes. Adding a new pricing rule means adding one entry to the object, with no edits to totalFor or its callers.
Use an object with methods instead of a bare function when a strategy needs several related operations or keeps its own state, such as a cache, a configuration, or a counter.
When a plain conditional is enough
Not every branch deserves a strategy. The PMI reference names simple branching as the procedural equivalent of this pattern, which means the branching is the same idea written without a boundary. A conditional is usually the better choice when:
Recommended Free Tools
- The set of options is fixed and small.
- The decision is made in one place and nowhere else.
- New options are unlikely to appear.
Introduce strategy functions or objects when the variation has to be hidden from the caller, chosen independently of the code that uses it, or extended by people who never edit the core function. If none of those apply, an if or switch is clearer and adds no indirection.
Adapter: translating a collaborator’s interface
The glossary defines Adapter as converting the interface of a class into another interface that clients expect. The JavaScript tutorial on this pattern frames it as a wrapper. Its payment examples present one common payment interface and delegate to a legacy system’s makePayment method or a third-party service’s chargeCard method. The adapter can also normalize the fields a result returns, so the application reads one shape.
A wrapper around a legacy method
The sketch below shows the idea. The legacy method’s name, arguments, and result fields differ from what the application wants, so the adapter maps between them. As with the Strategy example, this is an illustrative sketch, not production code:
Rank #4
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
function makeLegacyPaymentAdapter(legacy) {
return {
processPayment({ amount, currency = "USD" }) {
const result = legacy.makePayment(amount);
return {
status: result.success ? "completed" : "failed",
transactionId: result.transactionId,
amount,
currency,
};
},
};
}
Application code calls processPayment and never sees makePayment. Swapping the legacy service for a new one means writing a new adapter, not changing every caller.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Where adapters belong, and what they cannot fix
Place adapters at the edges of your system, where code meets a vendor or an old module. Keep vendor-specific names, units, and error shapes inside the adapter so the rest of the application speaks one contract. Write down the decisions the adapter makes, including default values such as the currency above, unit conversions, and how errors are reported.
Best Value
An adapter changes names and shapes. It does not change meaning. If two services handle failures differently, or one charges a card before confirming an order while the other does not, wrapping them behind one method hides that gap. Resolving it takes an explicit policy, such as timeouts, retries, or idempotency rules, and the adapter is only the place where that policy is applied. The tutorial’s example illustrates interface translation. It does not document how any real payment system behaves in production.
Adapter versus Facade
Both patterns can wrap complexity, which makes them easy to confuse. The glossary separates them by intent. An Adapter converts an interface that clients already expect to be a different one. A Facade provides a unified, higher-level interface to a subsystem. An adapter usually wraps one collaborator to match a contract; a facade usually wraps several parts to offer a simpler entry point.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Side-by-side comparison
| Axis | Strategy | Adapter |
|---|---|---|
| Main intent | Make implementations of a behavior interchangeable. | Make incompatible interfaces work together. |
| What changes | Which rule or algorithm the client uses. | How a collaborator is called and how its values are translated. |
| Client contract | A stable operation with selectable implementations. | A stable expected interface presented over a different interface. |
| Typical trigger | A behavior such as pricing, sorting, or validation varies by context. These are illustrative examples, not a complete list from the sources. | A legacy or third-party API, or a data shape, does not match the application’s contract. The cited tutorial uses payment interfaces. |
| Common mistake | Creating strategy types for fixed branching that never changes, which adds indirection with no real variation. | Letting vendor-specific details leak into callers, or renaming methods while ignoring differences in meaning. |
Deciding which pattern fits
- Does the caller already have the operation it needs, with several interchangeable ways to do it? That points to Strategy.
- Does a collaborator exist whose methods, arguments, or result shape differ from what your code expects? That points to Adapter.
- Is the choice fixed, local, and unlikely to grow? A conditional is enough.
- Are you only renaming a single function call with no change in meaning? A direct wrapper function may be clearer than a named pattern.
Strategy answers the question of which behavior to run. Adapter answers the question of how to talk to something that does not speak your language. Keeping those questions separate is what makes the choice straightforward.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




