Solved

3-Tier example required

Posted on 2013-02-07
12
310 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 45

Expert Comment

by:Kdo
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 44

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
 
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 45

Expert Comment

by:Kdo
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 44

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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 44

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 500 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 44

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 44

Author Closing Comment

by:AndyAinscow
ID: 38879221
Thanks
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Setting up SVN Server using Windows and Apache Purpose of the document:       This article will explain the process of how to configure SVN repository in a windows environment using APACHE web server. What is SVN? (http://subversion.tigris.org/) …
Before You Read The Article Please make sure you understand these two concepts: Variable Scope (http://www.php.net/manual/en/language.variables.scope.php) and Property Visibility (http://www.php.net/manual/en/language.oop5.visibility.php).  And to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now