i have a Sheet class which contains two attributes and each is a class

  1. summary (class)
  2. data (class)

summary and data has 1 attribute,df, which is a dataframe

my question is, am i right to say that since summary and data are classes:

  1. I shouldn't store summary and data directly as dataframes in Sheet class's attribute.

  2. I should store summary and data as objects and when main class wish to set summary/ data, i use Sheet's setter which uses summary/ data's setter to set the actual dataframe

Create sheet object in Main Class :

import Sheet
sheet = Sheet.Sheet() # create empty sheet
sheet.set_summary(new_df) # set summary
sheet.set_data(new_df) # set data

In Sheet Class :

import Summary
import Data

class Sheet:
    def __init__(self):
        self.name = None
        self._summary = Summary.Summary()
        self._data = Data.Data()

    def get_SheetSummary(self):
        return self._summary.get_summary()

    def set_SheetSummary(self,new_df):
        self._summary.set_summary(new_df)

    def get_SheetData(self):
        return self._data.get_data()

    def set_SheetData(self, new_df):
        self._data.set_data(new_df)

1 Answers

1
BreakBB On Best Solutions

If Summary and Data are classes which only have a dataframe as attribute and don't handle anything extra, I don't see a reason to create an extra class for them instead of holding the dataframes directly in your Sheet class. If things get more complicated you can still extract those attributes into separate classes.

If both classes do something more than just holding the dataframes then you're probably on a good way to have them capsulated in a class.