python abstraction

Discussion in 'App Development' started by Grinda21, Apr 16, 2023.

  1. Grinda21

    Grinda21

    I'm learning Python for a project and am a little puzzled about how to utilise abstraction and classes. (Since I'm not a very skilled coder, please excuse the basic level of my query.) I have a Java/Ocaml background, and what I've been doing is as follows: I have abstract classes that look like this for a graph and a graphadvanced (a graph with some extra fancy functions).

    Code:
    class AbstractGraph:
       def method01(self):
          raise NotImplementedError
       ...
    
    class AbstractAdvanced:
       def method02(self):
          raise NotImplementedError
       ... 
    I then have a graph implementation:

    Code:
    class Graph(AbstractGraph):
       def method01(self):
          * actual code *
    My question now is, can I do anything similar?

    Code:
    class Advanced(AbstractAdvanced, AbstractGraph):
       def method02(self):
          *actual code, using the methods from AbstractGraph*
    In other words, how can I describe Advanced's methods abstractly in terms of AbstractGraph's methods, and then feed Graph into a constructorto produce an instance of Advanced that utilises Advanced's definitions with Graph's implementation like this here?

    In regards of Ocaml, I'm attempting to treat AbstractAdvanced and AbstractGraph as module types, but I'm not sure how to make this work with Python.
     
  2. 2rosy

    2rosy

    Why are you asking this on ET?
    You probably want to pass an instance of graph into __init__ and link together
     
  3. You have to become advanced by years of study and self transformation .and then you wouldn't need python nor expect the mere typing a few statements to become or do what the name of the function implies
     
  4. 2rosy

    2rosy

    If your question is inheritance use super keyword