Skip to main content

I am struggling with the clean architecure. I have constructed a minimal example of how a usecase/interactor could talk to the database without being dependent on it:

The use case:

class SaveDatatoDBUseCase:
    def __init__(self, AbstractDB):
        self.db = AbstractDB

    def execute(self):
        self.db.save()

The gateway:

from abc import ABC, abstractmethod    
class AbstractDB(ABC):

    def __init__(self, value):
        pass

    @abstractmethod
    def save(self):
            pass

The Implementation for the Database:

class DBImplemtation(AbstractDB):
    def __init__(self):
        pass

    def save(self):
        print("INSERT INTO TABLE WHERE ...")

Wiring it altogether:

if __name__ == "__main__":
  dbImpl = DBImplemtation()
  save_to_db_Usecase = SaveDatatoDBUseCase(dbImpl)
  save_to_db_Usecase.execute()

yields to:

INSERT INTO TABLE WHERE ...

Is this how the communcation works between the UseCase/Interactor and the Database or I am I missing something here? I added a picture to clarify what I wanted to achieve with the code.

Can someone please confirm, whether this is a good minimal approach and if not, where I got this wrong or even what could be improved. Thank you in advance.

This is what I wanted to achieve

I am struggling with the clean architecure. I have constructed a minimal example of how a usecase/interactor could talk to the database without being dependent on it:

The use case:

class SaveDatatoDBUseCase:
def __init__(self, AbstractDB):
    self.db = AbstractDB

def execute(self):
    self.db.save()

The gateway:

from abc import ABC, abstractmethod    
class AbstractDB(ABC):

def __init__(self, value):
    pass

@abstractmethod
def save(self):
        pass

The Implementation for the Database:

class DBImplemtation(AbstractDB):
def __init__(self):
    pass

def save(self):
   print("INSERT INTO TABLE WHERE ...")

Wiring it altogether:

if __name__ == "__main__":
dbImpl = DBImplemtation()
save_to_db_Usecase = SaveDatatoDBUseCase(dbImpl)
save_to_db_Usecase.execute()

yields to:

INSERT INTO TABLE WHERE ...

Is this how the communcation works between the UseCase/Interactor and the Database or I am I missing something here? I added a picture to clarify what I wanted to achieve with the code.

Can someone please confirm, whether this is a good minimal approach and if not, where I got this wrong or even what could be improved. Thank you in advance.

This is what I wanted to achieve

I am struggling with the clean architecure. I have constructed a minimal example of how a usecase/interactor could talk to the database without being dependent on it:

The use case:

class SaveDatatoDBUseCase:
    def __init__(self, AbstractDB):
        self.db = AbstractDB

    def execute(self):
        self.db.save()

The gateway:

from abc import ABC, abstractmethod    
class AbstractDB(ABC):

    def __init__(self, value):
        pass

    @abstractmethod
    def save(self):
            pass

The Implementation for the Database:

class DBImplemtation(AbstractDB):
    def __init__(self):
        pass

    def save(self):
        print("INSERT INTO TABLE WHERE ...")

Wiring it altogether:

if __name__ == "__main__":
  dbImpl = DBImplemtation()
  save_to_db_Usecase = SaveDatatoDBUseCase(dbImpl)
  save_to_db_Usecase.execute()

yields to:

INSERT INTO TABLE WHERE ...

Is this how the communcation works between the UseCase/Interactor and the Database or I am I missing something here? I added a picture to clarify what I wanted to achieve with the code.

Can someone please confirm, whether this is a good minimal approach and if not, where I got this wrong or even what could be improved. Thank you in advance.

This is what I wanted to achieve

added 6 characters in body
Source Link
davidh38
  • 181
  • 3
  • 10

I am struggling with the clean architecure. I have constructed a minimal example of how a usecase/interactor could talk to the database without being dependent on it:

The use case:

class SaveDatatoDBUseCase:
def __init__(self, AbstractDB):
    self.db = AbstractDB

def execute(self):
    self.db.save()

The gateway:

from abc import ABC, abstractmethod    
class AbstractDB(ABC):

def __init__(self, value):
    pass

@abstractmethod
def save(self):
        pass

The Implementation for the Database:

class DBImplemtation(AbstractDB):
def __init__(self):
    pass

def save(self):
   print("INSERT INTO TABLE WHERE ...")

Wiring it altogether:

if __name__ == "__main__":
dbImpl = DBImplemtation()
save_to_db_Usecase = SaveDatatoDBUseCase(dbImpl)
save_to_db_Usecase.execute()

yields to:

INSERT INTO TABLE WHERE ...

Is this how the communcation works between the UseCase/Interactor and the Database or I am I missing something here? I added a picture to clarify what I wanted to achieve with the code.

Can someone please confirm, whether this is a good minimal approach and if not, where I got this wrong or even what could be improved. Thank you in advance.   

enter image description hereThis is what I wanted to achieve

I am struggling with the clean architecure. I have constructed a minimal example of how a usecase/interactor could talk to the database without being dependent on it:

The use case:

class SaveDatatoDBUseCase:
def __init__(self, AbstractDB):
    self.db = AbstractDB

def execute(self):
    self.db.save()

The gateway:

from abc import ABC, abstractmethod    
class AbstractDB(ABC):

def __init__(self, value):
    pass

@abstractmethod
def save(self):
        pass

The Implementation for the Database:

class DBImplemtation(AbstractDB):
def __init__(self):
    pass

def save(self):
   print("INSERT INTO TABLE WHERE ...")

Wiring it altogether:

if __name__ == "__main__":
dbImpl = DBImplemtation()
save_to_db_Usecase = SaveDatatoDBUseCase(dbImpl)
save_to_db_Usecase.execute()

yields to:

INSERT INTO TABLE WHERE ...

Is this how the communcation works between the UseCase/Interactor and the Database or I am I missing something here? I added a picture to clarify what I wanted to achieve with the code.

Can someone please confirm, whether this is a good minimal approach and if not, where I got this wrong or even what could be improved. Thank you in advance.  enter image description here

I am struggling with the clean architecure. I have constructed a minimal example of how a usecase/interactor could talk to the database without being dependent on it:

The use case:

class SaveDatatoDBUseCase:
def __init__(self, AbstractDB):
    self.db = AbstractDB

def execute(self):
    self.db.save()

The gateway:

from abc import ABC, abstractmethod    
class AbstractDB(ABC):

def __init__(self, value):
    pass

@abstractmethod
def save(self):
        pass

The Implementation for the Database:

class DBImplemtation(AbstractDB):
def __init__(self):
    pass

def save(self):
   print("INSERT INTO TABLE WHERE ...")

Wiring it altogether:

if __name__ == "__main__":
dbImpl = DBImplemtation()
save_to_db_Usecase = SaveDatatoDBUseCase(dbImpl)
save_to_db_Usecase.execute()

yields to:

INSERT INTO TABLE WHERE ...

Is this how the communcation works between the UseCase/Interactor and the Database or I am I missing something here? I added a picture to clarify what I wanted to achieve with the code.

Can someone please confirm, whether this is a good minimal approach and if not, where I got this wrong or even what could be improved. Thank you in advance. 

This is what I wanted to achieve

Rollback to Revision 1
Source Link
davidh38
  • 181
  • 3
  • 10

I am struggling with the clean architecure. I have constructed a minimal example of how a usecase/interactor could talk to the database without being dependent on it:

The use case:

class SaveDatatoDBUseCase:
def __init__(self, AbstractDB):
    self.db = AbstractDB

def execute(self):
    self.db.save()

The gateway:

from abc import ABC, abstractmethod    
class AbstractDB(ABC):

def __init__(self, value):
    pass

@abstractmethod
def save(self):
        pass

The Implementation for the Database:

class DBImplemtation(AbstractDB):
def __init__(self):
    pass

def save(self):
   print("INSERT INTO TABLE WHERE ...")

Wiring it altogether:

if __name__ == "__main__":
dbImpl = DBImplemtation()
save_to_db_Usecase = SaveDatatoDBUseCase(dbImpl)
save_to_db_Usecase.execute()

yields to:

INSERT INTO TABLE WHERE ...

Is this how the communcation works between the UseCase/Interactor and the Database or I am I missing something here? I added a picture to clarify what I wanted to achieve with the code.

Can someone please confirm, whether this is a good minimal approach and if not, where I got this wrong or even what could be improved. Thank you in advance.

   enter image description here

I am struggling with the clean architecure. I have constructed a minimal example of how a usecase/interactor could talk to the database without being dependent on it:

The use case:

class SaveDatatoDBUseCase:
def __init__(self, AbstractDB):
    self.db = AbstractDB

def execute(self):
    self.db.save()

The gateway:

from abc import ABC, abstractmethod    
class AbstractDB(ABC):

def __init__(self, value):
    pass

@abstractmethod
def save(self):
        pass

The Implementation for the Database:

class DBImplemtation(AbstractDB):
def __init__(self):
    pass

def save(self):
   print("INSERT INTO TABLE WHERE ...")

Wiring it altogether:

if __name__ == "__main__":
dbImpl = DBImplemtation()
save_to_db_Usecase = SaveDatatoDBUseCase(dbImpl)
save_to_db_Usecase.execute()

yields to:

INSERT INTO TABLE WHERE ...

Is this how the communcation works between the UseCase/Interactor and the Database or I am I missing something here? I added a picture to clarify what I wanted to achieve with the code.

Can someone please confirm, whether this is a good minimal approach and if not, where I got this wrong or even what could be improved. Thank you in advance.

 enter image description here

I am struggling with the clean architecure. I have constructed a minimal example of how a usecase/interactor could talk to the database without being dependent on it:

The use case:

class SaveDatatoDBUseCase:
def __init__(self, AbstractDB):
    self.db = AbstractDB

def execute(self):
    self.db.save()

The gateway:

from abc import ABC, abstractmethod    
class AbstractDB(ABC):

def __init__(self, value):
    pass

@abstractmethod
def save(self):
        pass

The Implementation for the Database:

class DBImplemtation(AbstractDB):
def __init__(self):
    pass

def save(self):
   print("INSERT INTO TABLE WHERE ...")

Wiring it altogether:

if __name__ == "__main__":
dbImpl = DBImplemtation()
save_to_db_Usecase = SaveDatatoDBUseCase(dbImpl)
save_to_db_Usecase.execute()

yields to:

INSERT INTO TABLE WHERE ...

Is this how the communcation works between the UseCase/Interactor and the Database or I am I missing something here? I added a picture to clarify what I wanted to achieve with the code.

Can someone please confirm, whether this is a good minimal approach and if not, where I got this wrong or even what could be improved. Thank you in advance.  enter image description here

added 2 characters in body
Source Link
davidh38
  • 181
  • 3
  • 10
Loading
Source Link
davidh38
  • 181
  • 3
  • 10
Loading