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 9024661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:04:45+00:00 2026-06-16T06:04:45+00:00

I have class Base . I’d like to extend its functionality in a class

  • 0

I have class Base. I’d like to extend its functionality in a class Derived. I was planning to write:

class Derived(Base):
  def __init__(self, base_arg1, base_arg2, derived_arg1, derived_arg2):
    super().__init__(base_arg1, base_arg2)
    # ...
  def derived_method1(self):
    # ...

Sometimes I already have a Base instance, and I want to create a Derived instance based on it, i.e., a Derived instance that shares the Base object (doesn’t re-create it from scratch). I thought I could write a static method to do that:

b = Base(arg1, arg2) # very large object, expensive to create or copy
d = Derived.from_base(b, derived_arg1, derived_arg2) # reuses existing b object

but it seems impossible. Either I’m missing a way to make this work, or (more likely) I’m missing a very big reason why it can’t be allowed to work. Can someone explain which one it is?

[Of course, if I used composition rather than inheritance, this would all be easy to do. But I was hoping to avoid the delegation of all the Base methods to Derived through __getattr__.]

  • 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-16T06:04:46+00:00Added an answer on June 16, 2026 at 6:04 am

    Rely on what your Base class is doing with with base_arg1, base_arg2.

    class Base(object):
        def __init__(self, base_arg1, base_arg2):
            self.base_arg1 = base_arg1
            self.base_arg2 = base_arg2
            ...
    
    class Derived(Base):
        def __init__(self, base_arg1, base_arg2, derived_arg1, derived_arg2):
            super().__init__(base_arg1, base_arg2)
            ...
    
        @classmethod
        def from_base(cls, b, da1, da2):
            return cls(b.base_arg1, b.base_arg2, da1, da2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class Base and classes Derived_1 , Derived_2 ... I need derived classes
I have base class BaseClass and derived classes DerivedA , DerivedB , and DerivedC
I have these classes: class Base { ... private: std::vector<X> v; }; class Derived
I have a class that looks like this: class Base < Library prelude some-value
I have a derived class that's a very thin wrapper around a base class.
Suppose I have class Base and Derived : public Base . I have constructed
I have a class Base. A and B extend Base. There is also a
I have a class hierarchy that looks like this: class Base<TElement> { public TElement
Let's say I have a class hierarchy. I could theoretically maintain its functionality with
Suppose I have a class like this class Base { private: int i; int

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.