Two Plus Two Publishing LLC Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > Other Topics > Programming

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 02-08-2012, 01:13 PM   #1
centurion
 
pEkvo's Avatar
 
Join Date: Dec 2006
Location: Belgium
Posts: 126
Application design

I am trying to build a tournament scheduler application. In the database I have one specific problem. I have the following database columns:
  • Hour (which is connected to the days that the tournament will run)
  • Official (the person who will officiate the match)
  • Field (the field on which the match will be played)

The problem I'm having is that if I 'connect' (use the PK of the above tables as a FK in my 'Match' table directly) I can have one official who can officiate two games at the same time OR I can have multiple officials who officiate on one and the same pitch at the same time OR I can have multiple matches on the same time on the same pitch.

How would I go about fixing this from a design point of view? I realise I could just limit the options one can choose programmatically but I'm really interested in how you can fix this from a design point of view.
pEkvo is offline   Reply With Quote
Old 02-08-2012, 03:27 PM   #2
enthusiast
 
Join Date: Mar 2009
Posts: 69
Re: Application design

I actually took the time to read this 3 times and still dont understand your question. Try not to abbreviate and act as if people you are asking have never heard of your problem (they havent... ).
swisstard is offline   Reply With Quote
Old 02-08-2012, 03:49 PM   #3
centurion
 
pEkvo's Avatar
 
Join Date: Dec 2006
Location: Belgium
Posts: 126
Re: Application design

Ok, my apologies. I see I typed "Database columns in the first line, that should be database tables".

Here's the problem breakdown:

I expect to have the following database tables: Tournament, Official, Day, Time, Location, Field, Team, Match and a couple of other ones which aren't important for my question.

If you think about the design of the 'Match' table you would probably have the following fields: TournamentID, Round, Date, Time, HomeTeam, AwayTeam, Result, Official, Field

Now say the application allows the tournament organisor to schedule the matches. He wants to plan the game between the NY Giants and the New England Patriots on the 12th of Februari at 6PM in Phoenix in the University of Phoenix Stadium officiated by John Doe. He would enter this via the UI and the record would be added to the Match database table.

Now say he wants to plan another match at the same time on the same day, he can't be allowed to pick the same stadium, and even if he picks another stadium, he can't pick the same official. I know how to prevent these problems from a development point of view, but I am interested to know how this kind of problem is handled from an analysis/design point of view. I.e. when drawing a domain model (problem model) or class diagram.
pEkvo is offline   Reply With Quote
Old 02-08-2012, 05:46 PM   #4
Pooh-Bah
 
Benholio's Avatar
 
Join Date: Jun 2004
Location: Atlanta, GA
Posts: 4,682
Re: Application design

So you're asking, how can you set up your database to enforce the basic rules such as, there can only be one match going on at a stadium at a time, an official can't be in 2 separate matches at the same time, etc?

The standard way to go about this is to define all these such dependencies in your data and then use those dependencies to create the proper tables. There are some nice algorithms for this, do some searching up on "database normalization" and "normal forms" for more information.

Yours is going to be a little bit tricky with the interplay between 'Date/Time' and the officials/fields/etc.
Benholio is online now   Reply With Quote
Old 02-08-2012, 07:33 PM   #5
Retired
 
Zurvan's Avatar
 
Join Date: Apr 2005
Location: On the front porch, yelling at kids
Posts: 32,227
Re: Application design

I'm going to assume that you have a table where you combine those three fields in a record, that constitutes a scheduled match?

You can make some unique keys of hour/official and hour/field. That prevents you from double-booking either resource.

That said, I'm not sure that's a better solution than decent business rules that prevent it from happening.
Zurvan is offline   Reply With Quote
Old 02-08-2012, 11:51 PM   #6
centurion
 
Penguino's Avatar
 
Join Date: May 2011
Posts: 99
Re: Application design

One way to do this would be to setup a stored proc that is used to create your Match records. It would contain the business rules that would prevent assigning an official to duplicate matches at the same time or to different facilites. Your code would then receive a status code that signifies either the record was succesfully created, or that an error occurred (the status code should designate why the error occurred).
Penguino is offline   Reply With Quote
Old 02-09-2012, 02:30 AM   #7
enthusiast
 
Join Date: Nov 2008
Posts: 88
Re: Application design

Quote:
Originally Posted by Penguino View Post
One way to do this would be to setup a stored proc that is used to create your Match records. It would contain the business rules that would prevent assigning an official to duplicate matches at the same time or to different facilites. Your code would then receive a status code that signifies either the record was succesfully created, or that an error occurred (the status code should designate why the error occurred).
Isn't it considered bad practice to code business rules in stored procedures? If you do this you'll split your business logic in two places, in the code and in the stored procedures. I'm not 100% sure about this tho
Viincent is offline   Reply With Quote
Old 02-09-2012, 04:19 AM   #8
Carpal \'Tunnel
 
gaming_mouse's Avatar
 
Join Date: Oct 2004
Location: taking notes on u (see profile)
Posts: 10,627
Re: Application design

These are business rules. If they get too complex to model in the database structure, just let the application code or ORM take care of enforcing them.
gaming_mouse is offline   Reply With Quote
Old 02-09-2012, 07:00 AM   #9
centurion
 
pEkvo's Avatar
 
Join Date: Dec 2006
Location: Belgium
Posts: 126
Re: Application design

Okay, many thanks for the replies. I'll use business rules to enforce these constraints.
pEkvo is offline   Reply With Quote
Old 02-09-2012, 10:15 AM   #10
centurion
 
Penguino's Avatar
 
Join Date: May 2011
Posts: 99
Re: Application design

Quote:
Originally Posted by Viincent View Post
Isn't it considered bad practice to code business rules in stored procedures? If you do this you'll split your business logic in two places, in the code and in the stored procedures. I'm not 100% sure about this tho
Generally speaking yes. However, this rule relates only to the creation of the record and could be considered immutable (it will never be the case that an official could suddenly be able to referee multiple matches at the same time). But for the most part business rules should be contained in the code
Penguino is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -4. The time now is 08:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.
Copyright © 2008-2010, Two Plus Two Interactive