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

  • Home
  • SEARCH
  • 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 8111113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:59:21+00:00 2026-06-06T01:59:21+00:00

I have a class structure like class A: def method1(self): return 1 class B:

  • 0

I have a class structure like

class A:
    def method1(self):
        return 1

class B:
    def method2(self):
        return 2

class C(A,B):
    def method3(self):
        return self.method1()+self.method2()

The Classes A and B provide functionality which class C gathers and enriches with some wrappers. Now it happens that I need a similar class C2 which is derived from a different implementation A2 instead of A: class C2(A2, B) with the same method3.

How would you realize such a design (C can derive from different implementation classes)?

If it has to do with advanced Python programming (meta-classes?) an example would be appreciated 🙂

  • 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-06-06T01:59:24+00:00Added an answer on June 6, 2026 at 1:59 am
    class CMixin:
        def method3(self):
            return self.method1()+self.method2()
    
    class C1(A,B, CMixin):
        pass
    
    class C2(A2,B, CMixin):
        pass
    

    Though the design you describe sounds like you want aggregation instead:

    class C:
        def __init__(self, a, b):
            self.a = a
            self.b = b
    
        def method3(self):
            return self.a.method1() + self.b.method2()
    
    
    c1 = C(a1, b)
    c2 = C(a2, b)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got the following class structure, and have plenty of classes like C
I have a class structure like abstract class Animal { public Animal(){ //init stuff..
I have a class structure like: abstract class A { String a; } class
Say I have a structure like: class SomeObject Public Name as String Public Created
I have a files structure like this: Class (folder): - User.php - Rule.php Scripts
I have classes structured like this: Public MustInherit Class A ' several properties End
Right now, I have the following class methods: def check_capacity(self, at_index) def update_capacity(self, at_index)
I have multiple classes of the following structure: class Thing(Base): id = Column(Integer, primary_key=True)
I have a tree-like structure of abstract classes and case classes representing an Abstract
I have the following class structure: class Organization { string Name; List<User> users; List<Organization>

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.