codementor on Nostr: Learn: Interface or abstract class? Interface: a contract with no instance fields ...
Learn: Interface or abstract class?
Interface: a contract with no instance fields (since C# 8 it can have default method bodies). Many per class. Best for "can do": IComparable, IDisposable, services you inject.
Abstract class: a partial implementation. Only one base class. Best for "is a" families that share code and state.
A common interview answer: start with an interface; add an abstract base class when several implementations repeat the same code.
#tip · TIP-050
Published at
2026-10-27 14:07:56 UTCEvent JSON
{
"id": "a2652e70e12b96527eab242e4f684329b520063ad724390f2fdbaaf668b4c070",
"pubkey": "e68a0856e90d9997b1f721e905249896412dd570399a987b2e8fd5e7fcfe2279",
"created_at": 1793110076,
"kind": 1,
"tags": [
[
"t",
"tip"
]
],
"content": "Learn: Interface or abstract class?\n\nInterface: a contract with no instance fields (since C# 8 it can have default method bodies). Many per class. Best for \"can do\": IComparable, IDisposable, services you inject.\nAbstract class: a partial implementation. Only one base class. Best for \"is a\" families that share code and state.\n\nA common interview answer: start with an interface; add an abstract base class when several implementations repeat the same code.\n\n#tip · TIP-050",
"sig": "650fe66b45024ad29cc98c16040c304b05b72678364b33a89064080a8627d81e6d98b8dae19c0886bf7169d80d52a8145c0735cdf13dda178ae96f2e9461faa4"
}