SShortSingh.
Back to feed

Head First Design Patterns: Why Composition Should Replace Inheritance by Default

0
·1 views

The 'Head First Design Patterns' book advocates preferring composition over inheritance when reusing or combining behaviors in object-oriented design. Inheritance forces subclasses to absorb all parent-class behavior, creating the fragile base class problem where changes to a superclass can unexpectedly break numerous descendants. When behavior varies across multiple independent dimensions, inheritance leads to combinatorial class explosion — for example, two dimensions with two options each already require four concrete classes, and adding a third doubles that count. Composition solves this by delegating behavior to separate, interchangeable objects, so new behavioral variations are added independently rather than multiplied. The principle does not ban inheritance entirely, but reserves it for stable, genuine is-a relationships that respect the Liskov Substitution Principle and remain shallow in hierarchy.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Why Unknown Processes Keep Reappearing in Windows Task Manager After Reboot

Windows users often notice unfamiliar processes in Task Manager that return after every restart, which can raise concerns about malware or unauthorized software. However, such processes are frequently launched automatically by legitimate applications, drivers, software updaters, or Windows itself through startup mechanisms like services, scheduled tasks, or registry entries. Investigating a recurring process involves checking its executable file path, digital signature, and publisher, rather than relying on the process name alone. Tools like Task Manager, PowerShell, and third-party monitors can help users identify what is triggering a process at boot. Security experts recommend combining multiple signals — location, signature, behavior, and origin — before drawing conclusions about whether a process is harmful.

0
ProgrammingDEV Community ·

Guide Shows How to Integrate AgentRouter as an LLM Provider in TradingAgents Framework

A developer tutorial published on DEV Community outlines how to add AgentRouter as a supported large language model provider within Tauric Research's open-source TradingAgents framework. The integration involves modifying several files, including registering AgentRouter's API endpoint and configuring WAF-bypass headers in the OpenAI client file. Developers must also update the model catalog to include AgentRouter's quick and deep model tiers, covering options from GPT-4o Mini to DeepSeek R1. Additional steps include setting an API key environment variable, bypassing strict model-name validation, and adding AgentRouter to the TradingAgents command-line interface. The guide is structured file-by-file to help users complete all changes systematically before reinstalling and restarting the framework.

0
ProgrammingDEV Community ·

Developer shares 5 rules for using AI agents to build Chrome extensions safely

A developer who has shipped eight Chrome extensions outlined five rules he now enforces when using AI agents to write code. The core concern is not whether the code runs, but what agents quietly add — such as extra permissions, external network requests, or new dependencies — without explicit instruction. His rules require the agent to seek approval before broadening permissions, adding analytics or CDN calls, modifying unrelated files, or introducing new packages. The fifth and most critical rule demands that any change affecting what user data is read, stored, or transmitted must be flagged for human review rather than decided silently by the agent. The guidelines reflect a broader principle: for small browser extensions, predictability, minimal permissions, and a clear privacy story matter more than implementation convenience.

0
ProgrammingDEV Community ·

How a One-Line Bug in Browser PDF Compression Shipped Empty File Downloads

A developer building a fully client-side PDF compressor discovered a subtle bug where pdf.js transferred the file's ArrayBuffer to its worker thread, silently detaching the original buffer and leaving it empty. This caused a fallback branch — designed to return the original file when compression offered no benefit — to instead deliver a zero-byte download to users. The issue went undetected in production because it only triggered for already-optimized PDFs, a case that had not been tested. The fix required copying the buffer before passing it to pdf.js, ensuring the original bytes remained accessible. The article also outlines broader challenges of browser-based PDF compression, including the trade-off between lossless structure rebuilding and lossy page re-rendering, memory risks on mobile, and the importance of never returning a larger file than the original.