Reputation: 803
Could you please recommend a design pattern for pages with tables.
There are three page types - AgeReport, PositionReport, SalaryReport.
Each page type has its own columns.
Columns have the same attributes (title, type, desc) across all page types.
So, probably it's better to create a list of Columns and use it across all page types.
It should be possible to:
- get titles of all columns for specific page type
- get titles of columns with specific type (int, double, string) for specific page type.
- get all table data for specific column for specific page type.
Image is attached.
I found only this solution:
- Columns should be as enum with attributes.
- Each page type should have List of Columns and in the constructor to define this list.
Upvotes: 0
Views: 434
Reputation: 1195
I would use a simplified Decorator. You have your base class that represents a report, with a list of columns and the rest of functionality (maybe a matrix with configurable number of columns too for the actual data). Then in the decorator classes you configure the base class objects as you need, setting the number of columns, the column names and so on. The advantage is you keep the common code in the base class and add report specific functionality in the decorator classes.
https://www.tutorialspoint.com/design_pattern/decorator_pattern.htm
At this url you can find an example, it might a more complex that what you actually need, but it should be easy to adapt to your scenario.
Upvotes: 2