I'm in development of a sample project in Android for a friend's phone that keeps track of his sales. At first, one of the requirements was to create yearly reports of this sales data. This would be stuff like most profitable week, total per quarter, total per month, and even yearly total, as well as compares for previous years (about 10 things total).

I created a class called YearlyReport that has all of these properties and they get populated from a database class that makes the appropriate SQL calls.

This data is displayed on a statistics page, but after seeing this my friend asked me to give the viewer the ability to select different weeks and display weekly data too (3 bits of information: the total for the week, the best day in the week, the worst day in the week). So as they change weeks in the year, he wants to see weekly data appear above the yearly data.

So now I need to do specific queries of weekly data, but display yearly data too. I feel really disorganized for some reason! At first I made a WeeklyReport object, and the database will say "ok for a given week W, I'll fill your WeeklyReport object and return it". Then I started wondering if I should do something smarter. Maybe combine something? Should there be inheritance? I'm missing something.

Is it OK to have a WeeklyReport and YearlyReport object? Should I combine them? If I do, it's still strange because the yearly report doesn't change much unless you move to a new year (not often), but the weekly does (depending upon the date).

2 Answers 2


Why don't you just create one class where you specify the date intervals as a parameter? I don't know your data model, but I guess it won't make any difference in code if you pass start_date=1/1/2014, end_data=31/12/2014 or end_data=07/012014 for the evaluation time?

Fort this approach, you will need an additional parameter list describing for the "aggregate intervals" (for example, if you want information about the best or worst month, your intervals are the 12 months of the year, if you want information about the best or worst day of the week, you just pass the 7 days of the specified week).

What remains is to calculate and pass the correct parameters to the class for a weekly or yearly report, but I guess this could be done by two simple functions, just using that Report class.

  • Thanks I think this is going to be the best way for the future (for example there may be cases later where I'll have to look at bigger intervals). :) Mar 5, 2014 at 13:27

I feel really disorganized for some reason!

You are feeling disorganised because you are trying to do OO design but constructing your classes around data, not behavior.

What is the behavior of WeeklyReport and YearlyReport? They seem to just hold data, which isn't an object.

Think about the system as a collection of little people talking to each other and telling each other what to do. I don't know the requirements fully, but I would guess if you do that no where will you have a ton of people for each type of report, since they would all do the same thing.

You might though end up with a person called "reporter" or "report constructor" and a "report" who can present themselves. If your software code was a little office with a ton of little people who would make the yearly report? How would she make the yearly report. Who would she talk to to construct the yearly report? How would the person present the yearly report (metaphor for displaying to screen) and to whom?

All these questions will lead you to a proper OO design that is far easier to manage than having a ton of report objects for each type of report you could produce.

  • The "M" in "MVC" would disagree that "just holds data" is not an object.
    – user22815
    Mar 5, 2014 at 15:56
  • 1
    Not at all, a model is a simulation of behavior. If your objects just hold data what are they modelling? Mar 5, 2014 at 16:19
  • That's right - it just holds data and displays it. Very small scenario as it's just my friend's phone. Very small # of sales. I'll think about the questions you posed, thanks! I was thinking just one class that holds data according to a particular time period as below. What do you think? Mar 5, 2014 at 17:08
  • I would focus less on holding data and focus on what the app does. It "create yearly reports of this sales data". So you need something to create a report. That object doesn't have to be a report itself. Thinking about the report is thinking about the data, when instead you should be thinking about behavior. When in doubt think of the real world. If you work in a business the yearly sale report doesn't create itself. That would be nonsensical. Something creates the yearly report and understands how to do that. Don't make the report an object itself unless you absolutely have to. Mar 5, 2014 at 17:19
  • So the app needs to display data. The object can be a report creator that takes in parameters, gets the data from the database accordingly, and then returns a Report class filled with the data. How does that sound? Mar 5, 2014 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.