0

so I am developing a library for dealing with trees (as graph structures). I already have a class Tree that implements many things.

I now want to create two new classes, let's say Tree2D and Tree3D, that will inherit from Tree, and for which I will add 2D and 3D geometry.

As I plan to have several methods that can be applied to both 2D and 3D geometry, I would like to create a class TreeGeometry, in which I will implement those methods, and then make Tree2D and Tree3D inherit from it.

However, I do not want that someone can instance TreeGeometry objects directly. In a sense, I want this class to be "private". I've read about abstract class, so I think it might be the appropriate thing, but I'm not sure that I can make such an abstract class inherit from Tree.

Any advice on how I should proceed ?

  • 3
    Does this answer your question? ["Private" (implementation) class in Python](https://stackoverflow.com/questions/551038/private-implementation-class-in-python) – dtc Feb 14 '20 at 15:46
  • I will definitely try it. Thank you. – Florian Ingels Feb 14 '20 at 15:47
  • 2
    On a side note, abstract classes would not be the right approach. Those are conceptually a class you reuse with inheritance. With a private class, I would be able to still use it somewhere else (maybe in the same file or separate class) but an abstract class would be saying "No one else can create an object with my name" – dtc Feb 14 '20 at 15:54

0 Answers0