Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API Design Question

while designing my api, i am thinking about how i would like to model the following behavior.

option 1 seems more logical, but with that comes enforcing invariants such as checking if the spreadsheet actually belongs to the workbook.

option 2 seems strange a spreadsheet knows how to remove himself, but in fact the spreadsheet has a reference to its parent workbook and can delegate the call directly to him.

or is this really not a valid case since the workbook would need to validate it spreadsheet no matter what?? thoughts?

Workbook wb = new Workbook("Finances");
Spreadsheet ss = wb.CreateSpreadsheet("Bob's");

// option 1:
wb.RemoveSheet(ss);

// option 2:
ss.RemoveFromWorkbook();

Thank You everyone

like image 653
Marco Avatar asked Dec 16 '22 09:12

Marco


1 Answers

I would use wb.Sheets.Remove(ss). This allows separation of responsibilities as the Sheets object is a collection of Spreadsheets. This also allows the concept later on that a sheet might be in multiple workbooks.

like image 154
Michael S. Scherotter Avatar answered Dec 22 '22 00:12

Michael S. Scherotter