Jost
Jost

Reputation: 5840

How to model the opening times of shops in an object oriented way?

What I need

I want to build an application that has a model "shop" in it. Each shop has opening times. These opening times can be quite complex. I think the complexity is best demonstrated by examples:

  1. A shop is open on Monday to Friday, from 10 to 18 o'clock.
  2. A shop is open on Monday to Wednesday from 10 to 18 o'clock, on Thursday from 14 to 18 o'clock, and from 10 to 14 o'clock on Friday.
  3. A shop is open on Monday to Sunday, from 10 to 18 o'clock, but only in a given time span, say from 18th April 2014 to 30th of May 2014
  4. A shop is open on the second Saturday of each month, from 10 to 16 o'clock.
  5. A shop is open all year from Monday to Saturday between 8 and 20 o'clock, but not on a couple of special days, e.g. 24th to 26th December and on easter Monday.

As you can see, there are many complex combinations.

The resulting data structure should support three things:

  1. Return a list of all time spans in which a shop is open for the next half year (or something in that order of magnitude)
  2. Return a human readable representation of the opening times which is shown to end users.
  3. The opening times of a shop will be entered by end users, which should be easily able to specify any of the above possibilities with a form (without training, its on a website).

My approach

I have tried to model this into an object structure. My current idea is this:

Problems I see

My greatest concern is usability: How do I print the opening times modeled like this, and how do the users enter them?

I'm open to other approaches. Nothing is implemented yet, and my stomach aches when thinking about the approach above...

Upvotes: 3

Views: 589

Answers (1)

Erwin Smout
Erwin Smout

Reputation: 18408

(As far as the data-modeling tag is concerned) One single entity :

OpeningPeriod(CalendarDay, OpeningHour, ClosingHour)

or

OpeningPeriod(OpeningTimeStamp, ClosingTimeStamp).

A full opening/closing schedule for any shop/org is a set of such opening periods.

Don't try to capture some sort of "generic all-encompassing predicative way" to describe any possible opening/closing schedule "in full", all exceptions and exceptions-to-the-exceptions included. You will fail because there is no end to the nature of the "exceptions". Also you will be hitting serious problems very quickly when you start trying to "prioritise" between rules that overlap.

Just try to build as much "standard" rule-based facilities in the UI as possible, plus a facility to manage the schedule at the lowest detail of OpeningPeriod, for handling any possible "exception left unhandled by the provided rules".

Upvotes: 3

Related Questions