Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

3-Tier example required

Posted on 2013-02-07
12
Medium Priority
?
317 Views
Last Modified: 2013-02-12
This is something I always feel I could do better - hence I am asking how others would approach this.

I am interested in how one would organise the following in a 3-tier model of data, business and user interface:

A record in a table (eg. booking) has a main type (MT) and a sub type (ST).
A MT has various STs eg.
Main type A) has STs of X and Y
Main type B) has STs of X and Z
Main type C) has STs of Y and Z
where X, Y and Z refer to text descriptions.

Table MT has a text description an an integer key
Table ST has an integer key, a foreign key (for the MT) and a text description

so:
A:   aaa, 1
B:   bbb, 2
C:   ccc, 3

in the sub types table there are the following (with ID, link to MT table and text which can be duplicated).
1, 1, xxx
2, 1, yyy

3, 2, xxx
4, 2, zzz

5, 3, yyy
6, 3, zzz


Now a booking is made
foo foo with MT of A and so for the ST only the xxx and yyy (with the keys of 1,2) should appear on the GUI.  eg. In a combo to select
Now another booking
bar bar with an MT of C so for the ST only yyy and zzz (with the keys 5, 6) should appear on the GUI.


What would be a suitable 3-tier organisation for the GUI to 'fill' the combo with the allowed STs and for the resultant new record to be written back to the database ?
0
Comment
Question by:AndyAinscow
  • 5
  • 5
  • 2
12 Comments
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 38864438
Hi Andy,

Before jumping into the deep end of the pool, let's look at the existing structure.  I've got an issue with the MT/ST relationship.  Ideally, the MT object should contain the keys for the ST object(s).  The structure that you've described is quite odd.


Kent
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 38864439
If the subtypes xxx in 1,1,xxx and 3,2,xxx are the exact same, then you really should have another table.

key, main_type
1, aaa
2, bbb
3, ccc

key, sub_type
1, xxx
2, yyy
3, zzz

main_type_key, sub_type_key
1, 1
1, 2
2, 1
2, 3
3, 2
3, 3

Then the subtype combo box would just be a join on the three tables.
0
 
LVL 45

Author Comment

by:AndyAinscow
ID: 38864574
Thanks to both.
OK, maybe I wasn't too clear on an aspect.  The xxx is the same text, but different sub types.

eg.
Think Accounting has an employee called John Smith and Planning has a different employee also called John Smith.  One selects the dept. then the employee.


ps.  I'm trying to reduce a more complex situation to a theoretical simple equivalent.
0
Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

 
LVL 37

Expert Comment

by:TommySzalapski
ID: 38864604
The "employee" should have some kind of employee id that uniquely identifies him and the tables should all use that.

I don't see where the challenge is. You populate the combobox with the names from the subtype table but have the id under the covers and you use the id everywhere.

I think I'm still missing something.
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 38864641
Hi Andy,

I'm still fuzzy on what you're trying to describe.

Main type A) has STs of X and Y
Main type B) has STs of X and Z
Main type C) has STs of Y and Z

Since "X" is a sub-type of "A" and "B", there are two rows in the ST table for "X", one for each related main type.

I'm not sure how the "John Smith" example applies.  Data is data and if two STs happen to have the same text, so what?  The "identity" of the ST is its primary key, not the associated data.


Kent
0
 
LVL 45

Author Comment

by:AndyAinscow
ID: 38864687
This is the critical part of my question:
I am interested in how one would organise the following in a 3-tier model of data, business and user interface:
...
What would be a suitable 3-tier organisation for the GUI to 'fill' the combo with the allowed STs and for the resultant new record to be written back to the database ?
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 38864922
I don't get the 3-tier part. You expose the info that should be exposed for whoever is viewing the combobox and use the unique ids in the background.

Data stored the database. UI just calls into the data model which queries the database and sends the list to the UI. I don't know what you mean by 'business' here.
0
 
LVL 45

Author Comment

by:AndyAinscow
ID: 38864955
My understanding of a 3 tier is the following:
data - handles the raw data.
UI - provides an interface the user can manipulate data without knowing anything about how and where the raw data is stored.
business - provides an interface where data is to be assembled into coherent objects for the UI.


I can think of a few ways to organise things in my given example - I am interested in hearing from others how they would organise it without me colouring their thoughts.
0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 2000 total points
ID: 38865365
Oh okay. I've seen that design paradigm called many different things.

So the UI needs a list for its combobox.
The UI It asks the business for a list.
The business queries the database, puts it into a list, and sends the list to the UI.
The UI presents the list as a combobox to the user.
The user selects an item from the combobox.
The UI sends the item to the business.
The business sends a query to the database to add the items to the database.

Note that there isn't (and by design, should not be) a single concept for this information. The whole point of the 3-tier thing is that the UI has no idea how the underlying info is stored and the data has no idea how the info will be presented.

So the data guy has one way of thinking about the info and the UI guy potentially has a completely different way of thinking about it. The business links them.
So you could completely change your UI and never have to touch your data and vice versa. If you are thinking about them at the same time, then you are doing it wrong.
0
 
LVL 45

Author Comment

by:AndyAinscow
ID: 38867047
Thanks.  I appreciate the reasoning behind a 3 tier design - just I am coding all three tiers.  Unfortunately one can pick up bad habits so this is like a revision excercise.
That is pretty much how I would have thought to be 'best'.
A couple of points I would like to discuss further.

When one changes the main type then different sub types become available.  Assume the UI choices are both in combo boxs.  How would a business object look to you?
(The data can be considered static for the duration, no requirement to keep querying the database.)
Would you have two - one for MT and one for ST, each essentially wrapping the underlying table.
Would you have just one that is used to fill both combos (eg. like a tree internally)



Linked with this at the UI level what are your thoughts about refilling the ST combo when the MT combo changes.  The form both are on handles that, or the MT combo having a handle to the ST combo and calling that directly to refill ?
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 38868309
I would not pull all the data in at once. I would have the UI capture the change event on the MT combobox, and any time it changes, I would send down for the ST list passing it the selected MT.
The business would just pass a list back up to the UI. No complex structures needed.
0
 
LVL 45

Author Closing Comment

by:AndyAinscow
ID: 38879221
Thanks
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Fluent Interface Design Pattern You can use the Fluent Interface (http://en.wikipedia.org/wiki/Fluent_interface) design pattern to make your PHP code easier to read and maintain.  "Fluent Interface" is an object-oriented design pattern that r…
Introduction Many of the most common information processing tasks require sorting data sets.  For example, you may want to find the largest or smallest value in a collection.  Or you may want to order the data set in numeric or alphabetical order. …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question