Simple inheritance? · Issue #78 · Knagis/CommonMark.NET (original) (raw)
Hi there!
Looking at the code, I'm trying to understand the rationale behind making a sealed Block
class, use a BlockTag enum to differentiate blocks, forcing to have all datas related to a specific kind of blocks appearing on the Block class, at the same level, making the Block class almost a blob class, rather than using a simple inheritance scheme? With the current code base:
- You can't easily extend with a new kind of block (both parser and formatters)
- It makes an additional allocation of an object for each block (not a huge deal, but I'm always tracking mem alloc to avoid annoying the sensitive GC)
- It is harder to track which data is specific to a kind of blocks,
- when you read the spec, you cannot match it easily with the code, typically things like
3.2 Container blocks and leaf blocks
We can divide blocks into two types: container blocks, which can contain other blocks, and leaf blocks, which cannot.
If you think it would benefit the lib, would you accept a PR for this kind of refactoring? (I'm not promising anything, just taking the pulse! 😅 )