mardi 16 juin 2020

Design pattern to apply chaining method calls

I would create a python class "ExcelFile" to handle adding multiple sheet in a workbook,

The function should be generic , so any one of the team could use it easily,

I did the developpement and everything is fine,my code is like :

def addSheet(df,"sheet_name1"):
    -- reading template
    -- add sheet1
    -- replace existing file

and after I call the function many times, it depends how much sheet i want to add,so:

addSheet(df1,"sheet_name1")
addSheet(df2,"sheet_name2")
addSheet(df3,"sheet_name3")

I want to refactor my code and put it into a python Class and implement a design pattern that will help me to do the job by calling

xls_file = ExcelFile().useTemplate("template_path").addSheet(df,"sheet_name1").addSheet(df2,"sheet_name2").writeXlsFile("filename")

What'is the name of the design pattern to do something like this?

Aucun commentaire:

Enregistrer un commentaire