Hacker News new | past | comments | ask | show | jobs | submit login

Inheritance is helpful when the domain is well-defined and the underlying problem is broadly similar enough to fill-in differences across what's being abstracted.

Some hand-picked examples of well-implemented inheritance in open source:

An example of where inheritance makes great sense is Django CBV (Class-based views), https://docs.djangoproject.com/en/1.11/topics/class-based-vi..., as well as Django REST Framework class views (http://www.django-rest-framework.org/api-guide/views/)

An example of where inheritance in the form of runtime metaprogramming makes sense is SQLAlchemy declarative and Django ORM.

An example where inheritance in the form of mixins make sense would be Django ORM, such as TimeStampedModel in django-extensions https://github.com/django-extensions/django-extensions/blob/....

An example where classes make sense in standard libraries would be (impure) interfaces such as csv.Dialect (https://github.com/python/cpython/blob/6aee6fb/Lib/csv.py#L2...)

An example of where inherited classes make sense in abstraction would be types (https://github.com/zzzeek/sqlalchemy/blob/master/lib/sqlalch...) and dialects in SQLAlchemy (https://github.com/zzzeek/sqlalchemy/tree/master/lib/sqlalch...)

As a closing note, It works a lot better when the use of inheritance symbolically represents actual standards (SQL, HTTP, and/or standard libraries API's) that developers already are familiar with, rather than abstract concepts meaningful only to the writer.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: