Skip to main content

All Questions

2 votes
3 answers
1k views

Should classes with business logic inherit from a class with helper methods, or vise-versa?

I have a codebase where some classes contain both "essential" business logic, and "incidental" complexity. I am considering a refactor where I leverage inheritance to improve the ...
MYK's user avatar
  • 343
2 votes
1 answer
288 views

Selective method inheritance

I have a lot of classes that are just a CRUD interface for microservices. They only have a param for the endpoint and some of the methods get_list / get_item / create / update / delete / activate / ...
xpy's user avatar
  • 129
2 votes
1 answer
170 views

Late inheritance, enforce subclass behavior in the future

A super class Transaction has two subclasses TransactionA and TransactionB. A Transaction is composed of multiple events that occur in time for a specific key (a file, a person, etc.). Depending on ...
Pobe's user avatar
  • 153
0 votes
2 answers
1k views

Should parent classes define methods using attributes of child classes?

I need to extend the parent classes of two child classes by adding shared methods to them. Starting with the initial definitions of the child classes: class ChildA(ParentA): pass class ChildB(...
pstatix's user avatar
  • 1,047
0 votes
1 answer
84 views

Classes for integrating both BitBucket and GitHub into our site (an inheritance and composition question)

I am writing a system of callbacks for BitBucket and GitHub which should modify our site on certain events in BitBucket or GitHub. It is reasonable to make a base class like GitIntegration to handle ...
porton's user avatar
  • 791
54 votes
5 answers
40k views

Are Python mixins an anti-pattern?

I'm fully aware that pylint and other static analysis tools are not all-knowing, and sometimes their advice must be disobeyed. (This applies for various classes of messages, not just conventions.) If ...
cat's user avatar
  • 734
9 votes
2 answers
911 views

Is Python's inheritance an "is-a" style of inheritance or a compositional style?

Given that Python allows for multiple inheritance, what does idiomatic inheritance in Python look like? In languages with single inheritance, like Java, inheritance would be used when you could say ...
Iain's user avatar
  • 450
2 votes
2 answers
755 views

Python OO problem

I started learning Python yesterday and I ran into a problem. I like to hear some thoughts on it. As an exercise, I decided to build a chatserver. As part of the exercise, I wanted to write some ...
Erik Ros's user avatar
3 votes
2 answers
2k views

One boilerplate class or many similar classes?

Lets say I'm trying to model a variety of objects that are virtually identical, the only difference being their class variables. Am I better off creating one boilerplate class and just calling the ...
Dan Oberlam's user avatar
  • 1,291
1 vote
2 answers
264 views

Python -- when should a class have-a rather than be-a?

This is related to "Extends is evil" vs. OCP? but separate because the idea of "implement the interface" doesn't exist in Python. I'm writing a class to pull some data off a webpage. It's ...
Patrick Collins's user avatar