Skip to main content
Stack Overflow
  1. About
  2. For Teams

Timeline for Conditional Inheritance based on arguments in Python

Current License: CC BY-SA 4.0

10 events
when toggle format what by license comment
Nov 27, 2024 at 0:39 answer added chrispitude timeline score: 0
Jan 18, 2021 at 14:15 vote accept Adithya Shiva
Jan 16, 2021 at 21:25 answer added Booboo timeline score: 12
Jan 16, 2021 at 21:00 comment added DisappointedByUnaccountableMod But don’t do what the answer from @SamiTahri suggests and dynamically create a class. That approach is a debugging and maintenance nightmare. Use statically declared classes. Yes it’s possible in Python, but that doesn’t make it advisable/sensible.
Jan 16, 2021 at 21:00 comment added Adithya Shiva In the actual code, class C is required because it processes data obtained from the parent classes. It needs to inherit methods either from Class A or Class B based on some initial conditions, do a bunch of stuff and then return some data based on the same. I can certainly do it by just copying all the methods in C to A and B and call the parent classes directly, just wanted to know if it is possible any other way. Thanks for your help!
Jan 16, 2021 at 20:54 answer added Sami Tahri timeline score: 0
Jan 16, 2021 at 20:53 comment added DisappointedByUnaccountableMod You should search for more about ‘factory’ methods/functions - this is jargon/terminology for a function which is called with some data that helps it decide which type of instance to return to the caller. IMO a factory implementation isn’t in itself very elegant (usually if-else, or perhaps dictionary-based for more complex choices) but has the advantage of of centralising in one place the decision-making about what class to create an instance of - in your case choosing between A or B. @chepner didn’t mention factory, but that’s what they are referring to.
Jan 16, 2021 at 20:52 comment added chepner You don't want a class C at all; you just want a function that returns either an instance of A or an instance of B, depending on the argument's passed.
Jan 16, 2021 at 20:32 review First posts
Jan 16, 2021 at 22:47
Jan 16, 2021 at 20:30 history asked Adithya Shiva CC BY-SA 4.0

AltStyle によって変換されたページ (->オリジナル) /