Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6843435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:14:41+00:00 2026-05-27T00:14:41+00:00

I have a number of classes which all share the same methods, only with

  • 0

I have a number of classes which all share the same methods, only with different implementations. In Java, it would make sense to have each of these classes implement an interface or extend an abstract class. Does Python have anything similar to this, or should I be taking an alternative approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:14:41+00:00Added an answer on May 27, 2026 at 12:14 am

    There’s a bit of a story behind interfaces in Python. The original attitude, which held sway for many years, is that you don’t need them: Python works on the EAFP (easier to ask forgiveness than permission) principle. That is, instead of specifying that you accept an, I don’t know, ICloseable object, you simply try to close the object when you need to, and if it raises an exception then it raises an exception.

    So in this mentality you would just write your classes separately, and use them as you will. If one of them doesn’t conform to the requirements, your program will raise an exception; conversely, if you write another class with the right methods then it will just work, without your needing to specify that it implements your particular interface.

    This works pretty well, but there are definite use cases for interfaces, especially with larger software projects. The final decision in Python was to provide the abc module, which allows you to write abstract base classes i.e. classes that you can’t instantiate unless you override all their methods. It’s your decision as to whether you think using them is worth it.

    The PEP introducing ABCs explain much better than I can:

    In the domain of object-oriented programming, the usage patterns for
    interacting with an object can be divided into two basic categories,
    which are ‘invocation’ and ‘inspection’.

    Invocation means interacting with an object by invoking its methods.
    Usually this is combined with polymorphism, so that invoking a given
    method may run different code depending on the type of an object.

    Inspection means the ability for external code (outside of the
    object’s methods) to examine the type or properties of that object,
    and make decisions on how to treat that object based on that
    information.

    Both usage patterns serve the same general end, which is to be able to
    support the processing of diverse and potentially novel objects in a
    uniform way, but at the same time allowing processing decisions to be
    customized for each different type of object.

    In classical OOP theory, invocation is the preferred usage pattern,
    and inspection is actively discouraged, being considered a relic of an
    earlier, procedural programming style. However, in practice this view
    is simply too dogmatic and inflexible, and leads to a kind of design
    rigidity that is very much at odds with the dynamic nature of a
    language like Python.

    In particular, there is often a need to process objects in a way that
    wasn’t anticipated by the creator of the object class. It is not
    always the best solution to build in to every object methods that
    satisfy the needs of every possible user of that object. Moreover,
    there are many powerful dispatch philosophies that are in direct
    contrast to the classic OOP requirement of behavior being strictly
    encapsulated within an object, examples being rule or pattern-match
    driven logic.

    On the other hand, one of the criticisms of inspection by classic OOP
    theorists is the lack of formalisms and the ad hoc nature of what is
    being inspected. In a language such as Python, in which almost any
    aspect of an object can be reflected and directly accessed by external
    code, there are many different ways to test whether an object conforms
    to a particular protocol or not. For example, if asking ‘is this
    object a mutable sequence container?’, one can look for a base class
    of ‘list’, or one can look for a method named ‘_getitem_’. But note
    that although these tests may seem obvious, neither of them are
    correct, as one generates false negatives, and the other false
    positives.

    The generally agreed-upon remedy is to standardize the tests, and
    group them into a formal arrangement. This is most easily done by
    associating with each class a set of standard testable properties,
    either via the inheritance mechanism or some other means. Each test
    carries with it a set of promises: it contains a promise about the
    general behavior of the class, and a promise as to what other class
    methods will be available.

    This PEP proposes a particular strategy for organizing these tests
    known as Abstract Base Classes, or ABC. ABCs are simply Python classes
    that are added into an object’s inheritance tree to signal certain
    features of that object to an external inspector. Tests are done using
    isinstance(), and the presence of a particular ABC means that the test
    has passed.

    In addition, the ABCs define a minimal set of methods that establish
    the characteristic behavior of the type. Code that discriminates
    objects based on their ABC type can trust that those methods will
    always be present. Each of these methods are accompanied by an
    generalized abstract semantic definition that is described in the
    documentation for the ABC. These standard semantic definitions are not
    enforced, but are strongly recommended.

    Like all other things in Python, these promises are in the nature of a
    gentlemen’s agreement, which in this case means that while the
    language does enforce some of the promises made in the ABC, it is up
    to the implementer of the concrete class to insure that the remaining
    ones are kept.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a number of classes which manipulate files in Java. I am
I have a number of data classes, which share an abstract base class so
I have to work with a large number of compiled Java classes which didn't
I have a number of classes that call say Trace.WriteLine(LogSomethingClassSpecific), in various methods all
I have inherited a Java project which includes a number of classes that are
I have a number of CSS attributes and Classes which get applied based on
I have a number of data classes representing various entities. Which is better: writing
I'm working with a number of 'helper' classes, which affectively have a bunch of
I have several obj-c classes, each of which require a number of constants that
I have a number of classes that are all related conceptually, but some more-so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.