# Mastering Growth: Flexibility Over Tradition! Newsy: Dev Concepts Weekly Published: 2026-06-08T13:00:00.300Z Source: https://newsyai.com/edition/5c08f04c-98cb-4485-9fe2-0adbc62213a6 Archive: https://newsyai.com/newsy/249754d5-9f20-4825-9aeb-daeec7c365c9.md --- **The Pros Know the Fundamentals Better!** **Weekly Edition #60** Three high-impact topics (about 90 seconds each) to compound your growth. Plain English, vivid metaphors, practical moves. --- ## 1) Composition over Inheritance: Build with LEGO Bricks, Not Rigid Family Trees Instead of locking behavior into deep parent-child relationships, design objects to *contain* other objects. This “has-a” approach keeps systems flexible when requirements shift. **Why this compounds** - **Adaptability booster**: Swap or extend behavior without rewriting entire hierarchies. - **Bug reduction**: Fewer surprises from unintended side effects in long inheritance chains. - **Team velocity helper**: New developers understand small, focused pieces faster. **Metaphor** Think of a car. You don’t inherit “engine” from a blueprint—you *contain* an engine, wheels, and seats. Need a hybrid? Just swap the engine module. No need to redesign the whole family tree. **How to do it** 1. Identify behaviors that might change and turn them into separate, injectable components. 2. Prefer passing collaborators into constructors over extending base classes. 3. Keep each component focused on one clear job. 4. Document the “has-a” relationships so teammates see the building blocks. 5. Refactor one inheritance chain at a time, starting with the most painful one. **Try this today** Pick a class that inherits from another. Ask: “Could this behavior live in a separate object I pass in?” Sketch the change on paper. **Further reading** - [Composition over Inheritance on Wikipedia](https://en.wikipedia.org/wiki/Composition_over_inheritance) - [Favor Composition over Inheritance (Gang of Four)](https://en.wikipedia.org/wiki/Design_Patterns) - [Practical example from Martin Fowler](https://martinfowler.com/bliki/CompositionOverInheritance.html) --- ## 2) Command-Query Separation: Let the Chefs Cook and the Waiters Serve Keep actions that change state (commands) completely separate from actions that only read data (queries). No method should both modify the world *and* return information about it. **Why this compounds** - **Fewer hidden bugs**: Side effects are obvious and predictable. - **Easier testing**: Queries are safe to call repeatedly; commands can be tested in isolation. - **Clearer code reviews**: Teammates instantly see what changes versus what only observes. **Metaphor** Imagine a restaurant. The chef (command) prepares the meal and changes the kitchen state. The waiter (query) only brings you the menu or checks if your table is ready. Mixing the two roles leads to chaos—burnt food or confused customers. **How to do it** 1. Name methods clearly: commands sound like verbs (“placeOrder”), queries sound like questions (“getOrderStatus”). 2. Ensure commands return nothing (or only a success indicator) and queries never modify data. 3. Move any mixed logic into two distinct methods. 4. Use the same naming convention across the codebase. 5. Review recent features for any method that both changes and reports. **Try this today** Scan one module. Find a method that both updates data and returns a value. Split it into two. **Further reading** - [Command-Query Separation on Wikipedia](https://en.wikipedia.org/wiki/Command%E2%80%93query_separation) - [Bertrand Meyer’s original formulation](https://en.wikipedia.org/wiki/Bertrand_Meyer) - [Practical CQS examples](https://martinfowler.com/bliki/CommandQuerySeparation.html) --- ## 3) Law of Demeter: Talk Only to Your Immediate Neighbors Objects should only interact with their direct collaborators, not reach deep into another object’s internals. This “don’t talk to strangers” rule keeps interactions local and understandable. **Why this compounds** - **Lower coupling**: Changes in one area don’t ripple through many layers. - **Simpler debugging**: Problems stay contained instead of hiding in long chains. - **Faster onboarding**: New readers don’t have to trace deep “train wrecks” of dots. **Metaphor** Think of a neighborhood. You ask your next-door neighbor for help; you don’t call their cousin three blocks away. The neighbor handles the request and returns a simple answer. **How to do it** 1. Limit method calls to objects you directly hold or receive as parameters. 2. Avoid chains like `customer.order.item.price`—add a helper method on the customer instead. 3. Introduce “middlemen” objects only when they genuinely simplify the conversation. 4. Use clear, narrow interfaces between modules. 5. During reviews, flag any dot-chain longer than two or three levels. **Try this today** Find one place in code with a long chain of dots. Introduce a simple method on the first object that hides the details. **Further reading** - [Law of Demeter on Wikipedia](https://en.wikipedia.org/wiki/Law_of_Demeter) - [Original paper by Lieberherr et al.](https://www.ccs.neu.edu/home/lieber/LoD.html) - [Practical refactoring guide](https://martinfowler.com/bliki/LawOfDemeter.html) --- ### Quick Recap - **Composition over Inheritance**: Build flexible systems with LEGO-style containment. - **Command-Query Separation**: Keep changes and observations in separate lanes. - **Law of Demeter**: Keep conversations local—only talk to your direct neighbors. Master these and your designs become easier to change, test, and understand—while you and your team stay productive. Pros build this way every day. You can too!