Dealing with duplicated code – HasProducts

 BaseArtisan and BaseOrder have products properties that behave the same way, to the extent that the original implementation of those properties involved essentially copying and pasting the code from one into the other. While that's probably not such a big deal in this particular case (since the hms_core class library is small, with few members, and there are only two places where that duplicate code would have to be maintained), in larger libraries, or if there was a lot of duplication of that code, it could become very problematic very quickly. Since Python allows classes to inherit from multiple parent classes, we can leverage that capability to define a new ABC—HasProductsthat will keep all ...

Get Hands-On Software Engineering with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.