The True Purpose of Classes and Functions: Beyond Reuse
The article argues that classes and functions serve as fundamental structural elements rather than mere tools for reuse, contending that excessive reuse can increase complexity while intentional redundancy simplifies maintenance, and advocating deep modules over shallow ones, illustrated by examples from Supercell, DingTalk, and a trivial shallow‑module code snippet.
This article explores the debate between code reuse and redundancy in software design, challenging the conventional DRY (Don't Repeat Yourself) principle. It argues that classes and functions exist not for reuse but as fundamental structural elements. Key points include:
Reuse introduces complexity and maintenance costs, while redundancy can simplify modifications.
Deep modules (simple interfaces with complex implementations) are preferable to shallow modules (complex interfaces with limited functionality).
Examples from companies like Supercell and DingTalk demonstrate how strategic reuse enhances product competitiveness.
Code example: public void addParameter(List params, String param) { params.add(param); } illustrates a shallow module with minimal value.
DaTaobao Tech
Official account of DaTaobao Technology
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.