<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/this-design-pattern-replaces-an-entire-class-hierarchy-gtifvyyf8" -->

---
title: This Design Pattern Replaces an Entire Class Hierarchy
description: A walkthrough compares three ways to model subscription plan variation in a SaaS billing system: subclassing per plan type, storing plan settings in plain...
canonical: https://daily.dev/posts/this-design-pattern-replaces-an-entire-class-hierarchy-gtifvyyf8
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: This Design Pattern Replaces an Entire Class Hierarchy | daily.dev
og:description: A walkthrough compares three ways to model subscription plan variation in a SaaS billing system: subclassing per plan type, storing plan settings in plain...
og:url: https://daily.dev/posts/this-design-pattern-replaces-an-entire-class-hierarchy-gtifvyyf8
og:image: https://api.daily.dev/og/posts/GtiFvYYf8.png
og:image:alt: This Design Pattern Replaces an Entire Class Hierarchy
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# This Design Pattern Replaces an Entire Class Hierarchy

**[ArjanCodes](https://daily.dev/sources/arjancodes)** · 15 min read · 1 upvotes · 0 comments

## Summary

A walkthrough compares three ways to model subscription plan variation in a SaaS billing system: subclassing per plan type, storing plan settings in plain dictionaries, and the type object pattern where plan variants are instances of a shared class. The type object pattern is presented as often the best fit because it groups meaningful data and rules (price, limits, features) into domain objects without exploding a class hierarchy. Guidance is given for when each approach fits: enums for simple categorical labels, type objects for data-rich variation, and true polymorphism/protocols for fundamentally different behaviors like fixed versus usage-based pricing. Storage tradeoffs (hardcoded Python files vs. database-backed plan configuration) are also discussed, along with a combined example using a pricing model protocol alongside the type object pattern.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=IdwdqdywNOM>

## Questions this post answers

### What is the type object pattern in software design?

The type object pattern represents variation using instances of a class rather than subclasses or the language's type system. Instead of creating a ProSubscription subclass, you create a SubscriptionPlan class and instantiate it as free, pro, or business objects, each holding its own price, limits, and features. It suits variation where each category carries meaningful data and rules, unlike a simple enum used for plain categorical labels.

_See daily.dev for more design-pattern breakdowns when deciding how to model business variation in code._

### When should I use an enum versus a full class for representing subscription plan types?

Use an enum when the variation is just a label or category with no attached data, such as a subscription status like active, past due, or canceled. Use a richer object, like the type object pattern, when the category carries meaningful information and rules, such as a pro plan having its own price, project limits, storage limit, and feature set that need to be grouped together.

_Developers weighing enums against domain objects can compare approaches like this on daily.dev._

### When does inheritance make more sense than the type object pattern for modeling subscription plans?

Inheritance and polymorphism fit better when subscription types represent fundamentally different behavior rather than just different configuration data, such as fixed-price billing charging a flat monthly amount versus usage-based pricing that calculates a final price from collected usage. These can be combined: a type object holding plan data can itself reference a pricing model protocol implemented differently by fixed and usage-based classes.

_Track practical guidance like this on daily.dev when deciding between inheritance and composition for billing logic._

## Similar posts on daily.dev

- [The Composite Design Pattern: How to Work with Individual Objects and Groups Through the Same Interface](https://daily.dev/posts/the-composite-design-pattern-how-to-work-with-individual-objects-and-groups-through-the-same-interf-6lvojd7t9) · freeCodeCamp · 0 upvotes · 0 comments
- [Design Patterns Suck](https://daily.dev/posts/design-patterns-suck-kei3cx9df) · iamluminousmen · 1 upvotes · 0 comments
- [Duck Typing and Inheritance in Ruby](https://daily.dev/posts/duck-typing-and-inheritance-in-ruby-q0pcc61at) · Ruby Flow · 0 upvotes · 0 comments

---

Tags: [#general-programming](https://daily.dev/tags/general-programming), [#python](https://daily.dev/tags/python), [#design-patterns](https://daily.dev/tags/design-patterns)

[View this post on daily.dev](https://daily.dev/posts/this-design-pattern-replaces-an-entire-class-hierarchy-gtifvyyf8)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"This Design Pattern Replaces an Entire Class Hierarchy","url":"https://daily.dev/posts/this-design-pattern-replaces-an-entire-class-hierarchy-gtifvyyf8","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/this-design-pattern-replaces-an-entire-class-hierarchy-gtifvyyf8"},"datePublished":"2026-09-18T15:02:25.321Z","dateModified":"2026-09-18T15:07:58.439Z","description":"A walkthrough compares three ways to model subscription plan variation in a SaaS billing system: subclassing per plan type, storing plan settings in plain...","image":"https://i.ytimg.com/vi/IdwdqdywNOM/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/IdwdqdywNOM/sddefault.jpg","isAccessibleForFree":true,"articleSection":"ArjanCodes","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"ArjanCodes","logo":"https://media.daily.dev/image/upload/s--QX1BCjx9--/f_auto,q_auto/v1777800752/logos/arjancodes?_a=BAMAMiWQ0","url":"https://daily.dev/sources/arjancodes"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/this-design-pattern-replaces-an-entire-class-hierarchy-gtifvyyf8","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"general-programming,python,design-patterns","timeRequired":"PT15M","video":{"@type":"VideoObject","name":"This Design Pattern Replaces an Entire Class Hierarchy","description":"A walkthrough compares three ways to model subscription plan variation in a SaaS billing system: subclassing per plan type, storing plan settings in plain...","thumbnailUrl":"https://i.ytimg.com/vi/IdwdqdywNOM/sddefault.jpg","uploadDate":"2026-09-18T15:02:25.321Z","duration":"PT15M","url":"https://api.daily.dev/r/GtiFvYYf8","embedUrl":"https://www.youtube.com/embed/IdwdqdywNOM"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"ArjanCodes","item":"https://daily.dev/sources/arjancodes"},{"@type":"ListItem","position":3,"name":"This Design Pattern Replaces an Entire Class Hierarchy"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/this-design-pattern-replaces-an-entire-class-hierarchy-gtifvyyf8#faq","mainEntity":[{"@type":"Question","name":"What is the type object pattern in software design?","acceptedAnswer":{"@type":"Answer","text":"The type object pattern represents variation using instances of a class rather than subclasses or the language's type system. Instead of creating a ProSubscription subclass, you create a SubscriptionPlan class and instantiate it as free, pro, or business objects, each holding its own price, limits, and features. It suits variation where each category carries meaningful data and rules, unlike a simple enum used for plain categorical labels. See daily.dev for more design-pattern breakdowns when deciding how to model business variation in code."}},{"@type":"Question","name":"When should I use an enum versus a full class for representing subscription plan types?","acceptedAnswer":{"@type":"Answer","text":"Use an enum when the variation is just a label or category with no attached data, such as a subscription status like active, past due, or canceled. Use a richer object, like the type object pattern, when the category carries meaningful information and rules, such as a pro plan having its own price, project limits, storage limit, and feature set that need to be grouped together. Developers weighing enums against domain objects can compare approaches like this on daily.dev."}},{"@type":"Question","name":"When does inheritance make more sense than the type object pattern for modeling subscription plans?","acceptedAnswer":{"@type":"Answer","text":"Inheritance and polymorphism fit better when subscription types represent fundamentally different behavior rather than just different configuration data, such as fixed-price billing charging a flat monthly amount versus usage-based pricing that calculates a final price from collected usage. These can be combined: a type object holding plan data can itself reference a pricing model protocol implemented differently by fixed and usage-based classes. Track practical guidance like this on daily.dev when deciding between inheritance and composition for billing logic."}}]}
```

