Home > OS >  using Class diagram to create baseclass in object oriented programming in python
using Class diagram to create baseclass in object oriented programming in python

Time:01-12

I am new to object-oriented programming I need to write a BankDataWriterBase base class in the following program using the class diagram given in below to the code. I cannot understand the complete thing that the class diagram has, anybody here to know & explain to me what they actually saying using the class diagram

import pandas as pd

class ExcelParser:
    def __init__(self):
        self.config = []       
    
    def extract(self, file_name):
        raw_excel=pd.read_excel(file_name,sheet_name=None,na_values= None,keep_default_na=False)
        return [x for k, v in raw_excel.items() for x in v[v.columns.intersection(self.config)].to_dict(orient='records')]

if __name__ == "__main__":
    conf = list(input("ENTER THE LIST HERE : ").split(','))
    file_name = input("enter the full path to the file : ")
    obj = ExcelParser()
    obj.config = conf
    print(obj.extract(file_name))

here is the class diagram for the BankDataWriterBase class, i have completed the EXcelParser class but i dont know how to approach the BankDataWriterBase class

enter image description here

CodePudding user response:

Since you already have an ExcelParser we'll start from there, But first perhaps take a look at this

ExcelParser will have an attribute config which is a List[str] and the function extract which you already have. You will need to store an instance of a BankDataWriterImpl.

BankDataWriterBase will be the base of BankDataWriterImpl(<-- needs to inherit from the base class) and will have some attributes: input_path, output_path and bank_identifier And a function write_file.

BankDataWriterImpl will have an extract_json function with a string argument and no return. BankDataWriterImpl will also store between 1 and n Tasks(so a list of tasks).

Each Task will have a run function that has no arguments and returns nothing.

Finally if you want to denote types in python take a look at the typing module

  •  Tags:  
  • Related