In Object Oriented Programming terms , how do i create a protected constructor in python. A base constructor that can only be called by derived classes and not directly.
Asked
Active
Viewed 138 times
0
-
1Generally if you want an uninstantiable base class, that's because it's an abstract class with abstract methods which requires a subclass to inherit the base class and implement those abstract methods. That solves that constructor problem automatically. Without that injunction, what's the rationale for disallowing the instantiation of the base class? – deceze Aug 31 '20 at 10:20
1 Answers
0
Fast answer: you can't, because the convention of the single underscore to indicate a protected access can't be used for constructor. Here you find a way to make a "private" constructor in python, I hope you can use it to arrange a solution for a protected visibility.

Rudy Barbieri
- 389
- 1
- 4
- 16