Skip to content

Instantly share code, notes, and snippets.

@Sedose
Last active July 22, 2025 08:59
Show Gist options
  • Select an option

  • Save Sedose/ab8c9cfea520d5292e1191fcf59b6dfe to your computer and use it in GitHub Desktop.

Select an option

Save Sedose/ab8c9cfea520d5292e1191fcf59b6dfe to your computer and use it in GitHub Desktop.
Conversation regarding huge (e.g. 5 levels) classes inheritance chains

Human: Large classes in programming

Claude: Large classes in programming are considered a sign of poor code design for several reasons:

Violation of the single responsibility principle A large class usually tries to solve too many tasks simultaneously. This makes the code confusing and difficult to understand. Each class should have one clearly defined role.

Maintenance complexity When a class has hundreds or thousands of lines of code, finding the right fragment becomes a real quest. Making changes turns into a dangerous operation - it's easy to break something in another part of the class.

Testing problems A large class is difficult to cover with unit tests. To test one function, you have to set up many dependencies and states, which makes tests cumbersome and fragile.

Reduced readability A developer has to keep a huge amount of details in mind to understand how the class works. This slows down development and increases the likelihood of errors.

Hindered reusability It's difficult to extract the needed functionality from a large class for use elsewhere. The code becomes less modular.

Solution - break large classes into several smaller ones, each with clearly defined responsibility. This improves architecture and makes code more maintainable.


Human: Given classes with 1000 lines (on average) and 7 levels of inheritance. Do I understand correctly that this inheritance actually creates huge classes under the hood. That is, even if a class is 300 lines, but transitively inherits from 7 others (multilevel inheritance), it simply contains all this mess within itself?

Claude: Yes, you understand absolutely correctly! This is one of the key problems of deep inheritance.

Effective class size When a class inherits from other classes, it indeed "contains" all their functionality. Your 300-line class with 7 levels of inheritance can actually contain thousands of lines of code if you add up all the inherited methods and fields.

Hidden complexity The most insidious thing is that this complexity is hidden. Reading the class code, you see only 300 lines, but to understand its complete behavior, you need to study the entire inheritance chain. This creates a false sense of simplicity.

Runtime problems An object of such a class in memory indeed contains all fields from all parent classes. When calling a method, an override somewhere in the middle of the hierarchy might trigger, making behavior unpredictable.

Architecture fragility A change in the base class can break classes at any level of inheritance. The deeper the hierarchy, the more places something can break.

Therefore, in modern development, composition is preferred over inheritance and hierarchies are kept as flat as possible (usually 2-3 levels maximum). Your example is a classic technical debt that needs to be refactored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment