-1

I must create a basic calendar of one year. I thought to use a generic Tree with the year like root, months as children of root, days as children of months etc...

Is it the right way?

I receive data of calendar from a library calendar of Python. For some days, or hours I must associate some events and I must represent the calendar with their events, in a table for example (every days of the calendar, days without events too).

  • 1
    You can't make this decision without knowing how you're going to consume whatever data you put in the calendar. – Philip Kendall Jun 6 '18 at 20:37
  • 1
    What language are you using? Is this a homework assignment? You haven't provided nearly enough information to answer your overly broad question. – Phil N DeBlanc Jun 6 '18 at 20:48
  • I must represent the calendar and each element (day or month or hour) could have some event and I must represent events too – Lorenzoi Jun 6 '18 at 20:53
  • 1
    You might be better off with just a List of CalendarEvents. It all depends on what you're trying to accomplish. Can you edit your question and add a lot more details? – Dan Pichelman Jun 6 '18 at 20:59
3

No, this isn't the right way.  In some sense, using a tree is a premature optimization over using a simple collection.  You can always add a tree or other indexing data structure later.

In the absence of any further information you should use the simplest possible data structure: a simple collection.  I'd recommend using a simple table as you'll find in SQL, with rows and columns: columns like start date/time, end date/time, event type, event name, etc...

As your knowledge of the domain expands, you'll be zeroing in on which columns and which tables to have.  Using a tree will hamper your agility — your ability to change as your project scope grows — whereas using a collection will not (and at worst, a collection will hamper your performance, and that's fixable).

When starting out, initially focus on the what of the domain, rather the howWhat columns, rather than how to organize (hierarchical) structure, how to insert, how to search.  If you need some optimized data structure or index, that can be done later.

Calendars imply long-term persistence anyway, which also suggests tables (and a database of some sort).  (With a database you can index your date columns for better performance if you find you need it.)

Eventually, you'll have a good understanding of the consuming application's query and command patterns, and its performance!  Now you can consider caching, other data structures, etc...


On another note, a tree as you describe will be very cumbersome.  (Another reason to start with a simple collection, and optimize something later.)

  • What if you have a two day meeting that goes from the 31st to the 1st?

  • Following your logic: Are you going to represent hours as children of days, minutes as children of hours, seconds as children of minutes, etc..?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.